Critical CSS in Shopify

December 24, 2021 | 5 min read
This is the process of reduce unused css.this is the technique that extracts the css for above the fold content in order to render content to the user as fast as possible. Above the fold is all the content a viewer sees on page load before scrolling. The remainder of the css can be loaded asyncronously.

1. Identification for Critical CSS

Tools like GT metrix,lighthouse,Page speed insights
Eliminate-render-blocking-resources-mobile

2. Firstly Check the Score and prepare documentation of readings

Example
Tools like GT matrix,lighthouse,Page speed insights
GT-Metrixhttps://gtmetrix.com/
LightHouse – Available In DeV Tools

3. File setup for critical CSS

i) To create your own CSS file go to store admin > Online Store > Themes > Actions > Edit code> Assets folder, and click on Add a new asset. On the pop-up select Create a blank file and name it whatever you want.

3.1 Identification for Preload webfonts

For example: critical.css
ii) save the file in theme.liquid on the top head section.
{{ ‘critical.css’ | asset_url | stylesheet_tag }}
iii) Main css file Add on the footer.
Example
< link rel=”stylesheet” href=”{{ ‘pre_theme.min.css’ | asset_url }}” type=”text/css” media=”print” onload=”this.media=’all’;onLoadStylesheet()” >

4. How do you make a critical in CSS

i) open Dev tools of your site, Go to Network window then select the CSS filter after that,
go to source > as shown in the picture > Remove all CSS Properties then,
Open critical.css(blank file) as a temporary in your next window.
How-do-you-make-a-critical-in-CSS
ii) After that in the next window(TAB) compare both CSS and start Integration both window
iii) Copy all used CSS as shown in your second Window after that paste it in the Blank.css file and Integrate.
NOTE: Take Above Fold only
iv) In this process you will see the changes.
critical-css
iv) so,solution is the first open your reference site and also your site after that integrate according to reference site.
v) After that Check the score of your website through (Tools)
NOTE: After that if you score
NOTE: INCASE IF YOUR SCORE UNDER PERFORMANCE THEN RE-INTEGRATE STRUCTURE AND CLS.
vi) After that you will get your result.

Leave A Comment