As of the moment, browsers still don't have the ability to dynamically load resources in <link>
based on its media
attribute.
See this article for a more in-depth discussion and implementation of this feature.
Option 1: Keep it as-is
If you're app isn't that big and the styles don't take up much bandwidth, it'd be best to keep them both intact. The cache is your friend. The initial load may be slow, but subsequent requests on the resources will be proxied through the cache.
Option 2: Load the styles with JavaScript
If your styles take about 500KB each, you're probably better off loading them asynchronously with JavaScript.
This will add much more complexity to your application (not to mention if you're using complex build tools like grunt, gulp, or webpack), but it can make initial load faster (or at least, seem faster).
If you want to pursue this path, you can simply include a small script at the bottom of your <body>
that checks the user's environment, loads the appropriate css file, inject the contents into a style tag, and append that style tag to the document <head>
.
Other notes
Personally, I think separating styles into landscape
styles and portrait
styles isn't the best way to organize your styles. A better code-separation technique might be to have different styles for different pages of your app, and have only the specific styles load based on the active page. (But it still depends if your layout relies heavily on the portait/landscape media query).
It goes without saying, but these all depend on the environment you're working with and the available server-side solutions you may have access to. It even depends as to how much effort you're willing to give just to reduce your initial load times by 10ms.
I'd say your best bet right now is to merge both files into a single one (so resources loaded pre-HTTP/2 loads faster) and keep it on all your pages. After the first load, it gets cached and that resource will load (almost) instantly. If you absolutely hate white screens, add a fun animated preloaded at the start of your app to entertain your users while they wait for your styles to load on the first render.