DEV Community

ahmed abdelaal
ahmed abdelaal

Posted on

3 1

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

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay