OS 2.0 - Multiple CSS Files (one per section)

OS 2.0 - Multiple CSS Files (one per section)

mrmarge
Visitor
1 0 2

Hey there,

 

We've come across the fact that the new OS 2.0 Dawn theme loads CSS files within the body. Each section has its own CSS file.

 

However I've seen that most updated themes and also almost all other Shopify OS 2.0 websites use the standard implementation of CSS files within the head section.

 

In my opinion separate CSS files per section might lead to loading files multiple times (if a section is uses more than one time) plus it would affect the Cumulative Layout Shift as well.

 

Can someone elaborate on why the Dawn Theme works like this any why almost all other Themes don't?

 

Thanks!

Best

Mark

Replies 2 (2)

KetanKumar
Shopify Partner
37047 3644 12029

@mrmarge 

yes shopify 2.0 allow  each section different css code add theme setting its easy

If helpful then please Like and Accept Solution.
Want to modify or custom changes on store Hire me.
- Feel free to contact me on bamaniyaketan.sky@gmail.com regarding any help
Shopify Partner | Skype : bamaniya.sky
PSD to Shopify | Shopify Design Changes | Shopify Custom Theme Development and Desing | Custom Modifications In to Shopify Theme | SEO & Digital Marketing

Philip_Sole
Shopify Partner
19 1 9

I thought this was a bit weird too. I think the file will be cached by the browser so won't be downloaded over the network twice. This seems to be the case when looking at the Network tab in Chrome developer tools. However, according to this Stackoverflow answer, the browser still needs to parse the file again which has a CPU overhead.

 

I guess it's a tradeoff between that approach or loading and parsing CSS unnecessarily if a section isn't used but it's CSS is included in a "monolithic" CSS file.

 

The Shopify CDN uses HTTP/3 which allows the browser to download multiple resources simultaneously. So this reduces the concern about more network requests. 

 

It would be good, I think, to be able to detect in liquid if a section had already been included to avoid parsing the CSS twice. But I don't think you can create a global liquid variable from a section that could store that data. I guess there will be some awkward workaround for that. 

Web design and development
webdesign@philipsole.com