How to Improve Lighthouse Score - Performance
Tags: performance, lighthouse, webdev, beginners
Published: 2020-12-14 12:54:38

![Lighthouse performance score](https://res.cloudinary.com/lindaojo/image/upload/v1607603313/Performance_f1zvh8.png)

This is the final article of the lighthouse series, I hope you enjoyed this series as much as I did. You can check out other Lighthouse articles below:


<a href="https://www.lindaojo.com/blog/how-to-improve-lighthouse-score-search-engine-optimization-seo/"  target="_blank" rel="noopener"> How to Improve Lighthouse Score - Search Engine Optimization (SEO)
</a>

<a href="https://www.lindaojo.com/blog/how-to-improve-lighthouse-score-accessibility/"  target="_blank"  rel="noopener"> How to Improve Lighthouse Score -Accessibility
</a>

<a href="https://www.lindaojo.com/blog/how-to-improve-lighthouse-score-best-practices/"  target="_blank"  rel="noopener"> How to Improve Lighthouse Score - Best Practices </a>

<br>

Don't know how to check your website's Lighthouse score? No problem, use this article <a class="link" href="https://www.lindaojo.com/blog/how-to-check-lighthouse-scores-on-chrome-or-firefox/" target="_blank" rel="noopener">How to Check Lighthouse Scores using Chrome or Firefox</a> as a guide.

<h3>Eliminate render-blocking resources</h3>

Render-blocking resources are either scripts or stylesheets.

Use the Coverage tab in Chrome DevTools to identify non-critical CSS and JavaScript. When you load or run a page, the tab tells you how much code was used.

Press <strong>Control+Shift+P</strong> or <strong>Command+Shift+P (Mac)</strong> and search "Show Coverage" to open the Coverage Tab shown below.

![Low Contrast](https://dev-to-uploads.s3.amazonaws.com/i/hz2qu98lbu290y20jclf.png)

Coverage measures the code used to render the present page, not the whole website. So just because a set of code is unused on your page does not mean it is totally useless.

<h4>- Remove render blocking scripts</h4>

Avoid importing scripts in the head section of your HTML.

Place scripts that impact the render of the page at the end of the body (before the body closure).

If a script is critical (marked partially or totally red) and must be placed in the head section, mark the script with async or defer attributes as shown below

```html
<head>
    <script defer></script>
    <script async></script>
</head>
```
With async, the file gets downloaded asynchronously and then executed as soon as it’s downloaded.

With defer, the file gets downloaded asynchronously but executed only when the document parsing is completed. Deferred scripts will execute in the same order as they are called.

<h4>- Remove render blocking stylesheets</h4>

Remove render-blocking stylesheets by preloading them. Suppose your page loads in the order below

```html
index.html
|--main.js
   |--styles.css
   |--animation.js
```

Main.js runs then styles.css and animation.js are downloaded. The page doesn't appear complete until those last 2 resources are downloaded, parsed, and executed. The order can be changed by preloading links in your HTML. This instructs the browser to download key resources as soon as possible.

```html
<head>
  ...
  <link rel="preload" href="styles.css" as="style">
  <link rel="preload" href="animation.js" as="script">
  ...
</head>
```

<h3>Avoid importing large 3rd party libraries within head tag</h3>

For instance instead of setting up font-awesome icons in the head of your html as shown below

```html
<head>
    <link rel="stylesheet" href="path/to/font-awesome/css/font-awesome.min.css">
</head>

```
You could use SVG icons instead, they are light and you don't have to install a library containing thousands of icons when you are just using 25. Font Awesome also lets you download the SVG versions of icons. It's a win-win situation.

<h3>Use CDNs to optimize images</h3>

CDN stands for Content Delivery Network. Using an image CDN, such as  <a href="https://cloudinary.com/" target="_blank" rel="noopener" class="link">Cloudinary</a> can significantly reduce the latency of your image delivery. Switching to an image CDN can yield a 40–80% savings in image file size.

An image URL indicates not only which image to load, but also parameters like size, format, and quality. The code snippet below displays an image using a Cloudinary image link

```html
<img src="https://res.cloudinary.com/lindaojo/image/upload/v1607603313/Performance_f1zvh8.png" alt="lighthouse performance report">
```

<h3>Use improved image formats such as Webp</h3>

New image formats such as <a href="https://developers.google.com/speed/webp" target="_blank" rel="noopener" class="link">Webp</a> are lightweight yet of great quality. Even though it is not supported by all browsers yet. You could use Webp images along with a fallback image as shown below.

```html
<picture>
    <source alt="Angela's cat, Bandit" srcset="images/cat.webp" type="image/webp">
    <img alt="Angela's cat, Bandit" src="images/team/cat.jpg">
</picture>
```

<h3>Remove unused CSS</h3>

Removing unused CSS from your production builds for maximum performance.
When you are building a website, you might decide to use a CSS framework like TailwindCSS, Bootstrap, MaterializeCSS, etc... But you will only use a small set of the framework, and a lot of unused CSS styles will be included.

You could use a tool like PurgeCSS to remove the excesses. PurgeCSS analyzes your content and your CSS files. Then it matches the selectors used in your files with the ones in your content files. It removes unused selectors from your CSS, resulting in smaller CSS files.

<a href="https://purgecss.com/#table-of-contents" target="_blank" rel="noopener" class="link">Get started with Purge CSS</a>

<h3>Minify CSS</h3>

Your CSS files usually contain unnecessary characters, such as whitespaces, comments, and indentation. In production, these characters can be removed to reduce CSS file size without changing how the browser processes the styles. This ensures that you are sending the smallest possible bundle to your users.

You can minimise your CSS using <a href="https://github.com/NMFR/optimize-css-assets-webpack-plugin" target="_blank" rel="noopener" class="link">optimize-css-assets-webpack-plugin</a>

The tips above will definitely give your lighthouse performance score the boost that it deserves.