Serve Static Assets With An Efficient Cache Policy

ahmedab84879559

ahmed abdelaal

Posted on April 18, 2022

Serve Static Assets With An Efficient Cache Policy

If you've ever run a Google Lighthouse analysis or pagespeed of your website, you've probably encountered an error like "Serve static assets with an efficient cache policy" or "Leverage browser caching".

Image description

What's a static asset?
Static assets are files or resources send to the user that the server does not change. Resources that do not change between different requests. Images, fonts, CSS, or JS files are good candidates to be considered as static assets in your website.

What is a cache policy ?
Image description

Why we need cache policy ?

When a browser requests a file, the server providing the file can tell the browser how long it should cache the file. If the user re-requests the file (by revisiting your site) in this duration, the browser can use the local copy instead of re-downloading it. In this way, HTTP caching helps load your pages faster for returning users , also reduce the traffic on your servers

A server tells the browser about caching a file through a cache-control header, It looks like this:

Cache-Control: public, max-age=31536000

💖 💪 🙅 🚩
ahmedab84879559
ahmed abdelaal

Posted on April 18, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related