When you set the expiration time to 30 days, static files like CSS, JS, or images are cached in the visitor’s browser for that duration. Here’s what happens when the visitor revisits your site after 20 days:
- If the file hasn’t expired (still within 30 days): The browser will serve the cached version without requesting a new one from the server. This saves bandwidth and improves load time.
- If the file has changed on the server: The browser compares the file’s version using its
Last-Modified or ETag headers (if configured). If a new version is detected (e.g., due to file changes), the browser downloads the updated file, overriding the cached version.
Hope this helps!
Thread Starter
Alwin
(@wp-opti)
Thank you, so if I understand correctly a browser never serve the old (browser) cached version without cheking for a new version first?
You’re correct! Even if the browser has cached the file locally (e.g., within the 30-day expiration period), it will still check with the server to ensure the cached version is up-to-date. This happens via headers like Last-Modified or ETag. If the file hasn’t changed, the browser will use the cached version to save bandwidth and speed up loading. If a new version exists, it will download and replace the old cached file. So, the visitor won’t see an outdated version as long as these headers are correctly configured.