Websites
Understanding caching: why changes are not visible straight away
Caches make websites fast. They are also why some visitors still see the old version after an update, and why an error page suddenly reports the wrong status.
In short
- Browsers, servers and networks store responses temporarily so they are not reloaded every time.
- HTML pages should be cached only briefly; versioned CSS, script and image files for a long time.
- After every upload, check whether the cache really delivers the new version.
What it is about
A new package has been uploaded and all checksums match. Still, a colleague calls: they can still see the old home page. Someone else reports that the new stylesheet is missing and the page looks broken. In almost all such cases the upload is not to blame, but a cache.
Caches sit in several places: in every visitor’s browser, on the web server and often in a network in between that brings content closer to users. They are intended, because they make websites fast and relieve the server. You just have to control what is cached and for how long.
How it works
The rules are described in the RFC 9111 standard. With the Cache-Control header, the server tells the browser how long a response is valid and whether it has to be checked before reuse. A simple split has proven itself. HTML pages get no or a very short cache time, or no-cache, so that the browser briefly asks on every visit whether there is a new version. CSS, scripts, fonts and images, on the other hand, carry a version in the file name and may stay unchanged in the cache for a year. If the file changes, its name changes, and the browser automatically loads it again.
On the server there is often an additional page cache that stores finished responses. It has to be cleared deliberately after every upload.
Where it goes wrong
The most common mistake is files without a version in their name. If site.css is overwritten, browsers keep the old version until their cache time expires. New pages and old styles then do not fit together. The second classic is the forgotten server cache. In one project, an error page occasionally returned status 200 instead of 404 because the server had cached an earlier response. To visitors everything looked right, but to search engines the page was suddenly valid content.
A third mistake is checking in your own browser. If you only look yourself after an upload, you may be seeing your own cache. A request that bypasses the cache and checks status code, headers and checksum is reliable.
How to proceed
Set short cache times or no-cache for HTML. Deliver CSS, scripts, fonts and images with a version or checksum in the file name and allow long cache times with immutable. Clear server and network caches deliberately after every upload. Check live with a request that bypasses the cache, and verify status code, cache headers and checksum. And test error pages again for the correct status code after clearing.
Read more: Measuring PageSpeed properly: lab data, field data, fluctuations, HTTP status codes and soft 404s: what your error page tells Google and Web fonts and loading time: fast without layout shifts.
How Airnite helps
We set up caching rules that make your website fast and still show changes immediately, with versioned files, suitable headers and a live check after every upload. When outdated pages or wrong status codes cause problems, we find the place where the cache is stuck.
Checklist
Sources
Every fact in this article is based on the following publications. Primary sources are marked.
- IETFRFC 9111: HTTP Caching
- web.dev (Google)Prevent unnecessary network requests with the HTTP Cache
- MDN Web DocsHTTP caching
Matching services
Read on
Measuring PageSpeed properly: lab data, field data, fluctuations
The PageSpeed Insights score is often read like a school report. But it is only a snapshot under lab conditions. Anyone who wants to improve must know what is being measured and what is not.SEO3 minHTTP status codes and soft 404s: what your error page tells Google
A nice error page helps visitors. For search engines, however, what counts is not what it says but which number the server sends with it. If it is wrong, you get soft 404s, orphaned pages and lost rankings.Websites3 minWeb fonts and loading time: fast without layout shifts
A beautiful corporate typeface is part of the brand. Embedded without a check, it often weighs more than all the images on a page and makes text jump while loading. A few changes make it light.Current incidents and warnings are covered in the Zero Day magazine. Go to the magazine