⚡ Every Web Developer should know what Critical CSS is and how to use it
Using critical CSS and defer non-critical CSS can boost your website's performance which is becoming more important!
👇 Learn how to extract critical CSS and defer non-critical CSS
▶️ What exactly is critical CSS?
Critical CSS is any CSS that is relevant for elements being displayed above the fold. Above the fold are all elements that are rendered within a user's viewport when visiting your website. Anything else is non-critical!
▶️ How can you extract your critical CSS?
One of the easiest methods to get quickly started is by using an online tool.
There are plenty out there.
For our example, we will use sitelocity.com/critical-path-….
Just enter your domain, and generate your critical CSS in a second.
▶️ How should you load critical CSS?
Critical CSS should always be loaded at first.
Make sure to put it directly into your header and always inline it.
Loading it over a file will require a request which may slow the loading down!
▶️ How to load non-critical CSS?
We require to load it asynchronously.
You want to listen to the 'onload'-event and set the rel attribute to the stylesheet. This may look a bit ugly, but it is currently the best way.
Also, make sure to include a no-script version!
▶️ What are the top 3 online critical CSS generators?
⚡ As a Web Developer, you should always minify your CSS/JS!
Minifying your code is crucial to ensure your website is fast and good performing for modern SEO!
👇 Learn how to minify your CSS/JS in seconds!
1️⃣ Why you should minify CSS/JS
Minifying your CSS/JS reduces its size, no unnecessary white spaces, and no comments are loaded.
Those changes can drastically decrease the payload size of your request.
For JS, it even can strip down function and variable names!
2️⃣ How much does minify save you?
In our example below, we have a simple portfolio page.
The default CSS was not minified and had a size of 2.1 kb.
The minified outcome is 1.1kb, which is nearly 50% savings.