Course contentsShow
← Web Development
Lesson 2146 of 2,98239. Network PerformanceFree lesson

Immutable Assets Pattern

Caching fingerprinted assets forever with Cache-Control: immutable and long max-age.

Immutable Assets Pattern

You'll learn how to cache fingerprinted assets forever using Cache-Control headers for maximum performance.

The Core Idea

When you version your static assets (JavaScript, CSS, images) with content hashes in their filenames—like app.a3f8b2.js instead of just app.js—you've created immutable assets. The filename changes whenever the content changes, meaning app.a3f8b2.js will always contain the same code forever.

This allows you to safely tell browsers: "Never revalidate this file. It will never change."

How It Works

The immutable directive in Cache-Control tells browsers that the resource will never be modified during its freshness lifetime. Combined with a very long max-age, this eliminates unnecessary revalidation requests:

Cache-Control: public, max-age=31536000, immutable

This header means:

  • public: Any cache can store it
  • max-age=31536000: Cache for 1 year (in seconds)
  • immutable: Don't revalidate even if the user hits refresh

Without immutable, browsers often revalidate cached files when users reload a page, sending requests with If-None-Modified or If-Modified-Since headers. With immutable, even refresh skips revalidation.

Think of It Like This

Imagine a published book with an ISBN. The content of that specific ISBN never changes. If you want a new edition, you get a different ISBN. The immutable assets pattern works the same way—each filename is like a unique ISBN that never changes its contents.

Key Takeaway: Use Cache-Control: public, max-age=31536000, immutable for fingerprinted assets to eliminate revalidation requests and maximize cache hits, knowing new content automatically gets a new filename.