Reputation: 135
I have a website with several pages (for example 1.htm and 2.htm) and some script files, referenced from this page.
My .htaccess file contains this code:
FileETag MTime Size
<ifModule mod_expires.c>
ExpiresActive On
ExpiresByType text/html "access plus 1 day"
ExpiresByType text/css "access plus 1 week"
ExpiresByType text/javascript "access plus 1 week"
ExpiresByType application/javascript "access plus 1 week"
ExpiresByType application/x-javascript "access plus 1 week"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
</ifModule>
I visit page 1.htm, then change script file and navigate to page 2.htm. I expect that Apache will return new Etag/LastModified values and the script file will be updated. But it returns old values. What is wrong?
When I refresh the page I get new Etag/LastModified values.
Upvotes: 0
Views: 1469
Reputation: 46040
The point of caching is that you don't have to download the file again for the specified time.
So this line:
ExpiresByType text/html "access plus 1 day"
Means if you visit the page on the same day then the page will be served from the cache rather than from the server. Therefore you will not get the new page nor the new Etag/Expiry headers. If you load developer tools in Chrome for example, you'll see the page is loaded "from cache".
If it's still in the cache and you refresh it, then the browser does double check with the server if the file has changed returning a 301 if it hasn't, and redownloading the page if it has changed (including new headers). But with a normal page load it doesn't even do this check with the server and serves straight from your cache. This is the way it's supposed to work.
So with above setting visitors to your site could still be seeing the old version of your page for up to 1 day after you change it.
You could add must-revalidate to the cache headers so it will cache and also check with the server every time but that loses most of the benefit of caching.
Btw, as an aside, you shouldn't use Etags with Apache as they don't work when also using gzip. More details here: https://www.tunetheweb.com/performance/http-performance-headers/etag/
Upvotes: 1