⚡ Every Web Developer should know how to find unused code in their application
A lot of unused code can slow down your website. It is blocking the main thread with parsing, compiling, and executing the code.
👇 Learn how to find unused code in seconds
1️⃣ Using chrome dev tools
Chrome dev tools have a coverage tab that can reveal unused CSS. You can access this tab by:
- Open Dev Tools
- STRG+ Shift + P
- Searching "Coverage"
- Select "Start instrumenting coverage and reload the page"
👇
This does open a new tab in Chrome and displays all the files that may include unused code.
You can already learn a lot from these files alone, as in our example, there are fonts loaded that are never used. Easy to clean up.
👇
Clicking one of these source URLs will open up these files in your Chrome Dev Tools and highlight line-by-line if they are unused or not.
For CSS, this mostly checks whether the class is used. Logical usage of properties that may are inheriting is not checked!
👇
🔴 Slow down when checking these files! Not everything is secure to be deleted there.
It does check exactly the current state in your browser and nothing more. CSS that is applied to dynamic content may be marked as unused when it is not.
👇
If you start toggle these states and dynamic content, the coverage will update as soon as these classes are used.
An undeniable example is a light/dark mode.
It could also be some popups, dialogs, content being revealed with javascript, etc.
👇
Not every unused content can be avoided! So do not expect to get 100% used code straight away.
Usually, using third-party libraries will bring up many unused lines code, as you do not use all their functionality. Being aware of it is already a good point when evaluating libs.
2️⃣ CI tools
There are 3 well-known packages to remove your unused CSS while building a page:
⚡ 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.
⚡ 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.