Track 02 · Lesson 14 of 17Inside the browser
- 01Events and bubbling
- 02What fires when you click or type
- 03Keyboard, input and focus events
- 04Default actions and preventDefault()
- 05Event delegation
- 06Listener options and cleanup
- 07Custom events
- 08Debounce and throttle
- 09Events in React
- 10The event loop
- 11Don't block the main thread
- 12The rendering pipeline
- 13Core Web Vitals
- 14HTTP caching
- 15Responsive design
- 16SEO basics
- 17Service workers and offline
HTTP caching
Lesson 14 of 17· 8 min
The fastest request is the one never made. The Cache-Control header tells browsers and CDNs how long they may reuse a file, and an ETag lets them ask "has it changed?" cheaply. Load the page, let time pass, deploy a new version, and see what users get.
Deploy and see what users get
Try “The classic bug” first
Common setups
File name
Same name every release.
Cache-Control
Server has v1 as app.js. Browser cache: empty. Clock: 0 min.
The words that matter#
max-age=N: reuse this copy for N seconds without asking.no-cache: keep a copy, but check with the server before every use. Despite the name, it caches.no-store: never keep a copy at all.immutable: this file will never change under this name, so don't even check.ETag: a fingerprint of the file. The browser sends it back inIf-None-Match, and if nothing changed the server answers304 Not Modifiedwith no body.
Why hashed file names win#
A file called app.js that's cached for a year will stay stuck on the old version after you deploy. Put a hash of the content in the name, app.3f9a2c.js, and every new version is a brand-new URL. The HTML points to the new name, so the old file can sit in caches forever without harming anyone. Next.js and Vite do this for you.
Check yourself