#1026 Posted in ‘Route 66’

Latest post by Lefteris Kavadas on Tuesday, 18 April 2023 23:43 EEST

Gina Geick
Hi there,
I am loading style sheets according to screen size - so, desktop, mobile-portrait, mobile-landscape, tablet-portrait, and so on.
As soon as I enable CSS optimize, my layout breaks across all devices. Would that be because ALL of them are thrown together and there are duplicates?

Any insight is appreciated!
Gina G.

Lefteris Kavadas
Hi Gina,

Can you please provide more details? How do you detect the screen size and load different stylesheets? Are you using Javascript?
A link to your page would be very helpful.

Regards

Gina Geick
Sure thing. No javascript.

<link rel="stylesheet" type="text/css" href="https://www.firecoders.com/templates/2022/css/common.css">
<link rel="stylesheet" media="screen and (min-width: 200px) and (max-width: 649px) and (orientation:portrait)" href="https://www.firecoders.com/templates/2022/css/mobile-portrait.css" />
<link rel="stylesheet" media="screen and (min-width: 200px) and (max-width: 901px) and (orientation:landscape)" href="https://www.firecoders.com/templates/2022/css/mobile-landscape.css" />
<link rel="stylesheet" media="screen and (min-width: 599px) and (max-width: 1199px) and (orientation:portrait)" href="https://www.firecoders.com/templates/2022/css/tablet-portrait.css" />
<link rel="stylesheet" media="screen and (min-width: 801px) and (max-width: 1200px) and (orientation:landscape)" href="https://www.firecoders.com/templates/2022/css/tablet-landscape.css" />
<link rel="stylesheet" media="screen and (min-width: 1201px) and (orientation:landscape)" href="https://www.firecoders.com/templates/2022/css/desktop.css" />

Live site https://www.hawkeye.ca

Thanks.

Lefteris Kavadas
Hi Gina,

Using media queries in media attribute of the link tag does not affect the loading of CSS files. It just tells the browser which file should use, not load . The browser needs to load all those files in order to do this. That's why this approach has no benefits when considering the site loading time.

You can verify what I am saying by using the network inspector of your browser. You will see that all the CSS files are loaded in every request, for every screen size.

Now back to your question, Route 66 does not support this at the moment. Route 66 combines all CSS files in one and places the result in the page source, as you noticed correctly. This is a recommendation from Google Core Web Vitals / PageSpeed in order to improve page rendering time. More information can be found at https://web.dev/css-web-vitals/.

So since Route 66 combines all files, and your media queries are in the link media attribute instead of the source code we end up with a broken layout.

I recommend to just disable CSS optimization in Route 66 options. For any new site, you might want to consider using media queries inside your CSS source code.

Please let me know if you have any questions.

Regards

Gina Geick
Ok, thank you.

Lefteris Kavadas
You are welcome.

Note: An active subscription is required in order to get support for our paid extensions. For our free extensions, if you don't have an account, register and then submit your support request.  In case you just want to ask a question, you can also use the contact form .

Firecoders
Are you using our extensions? Please post a review at the Joomla extensions directory!
Post a review