Search code examples
apache.htaccessmod-expires

Apache still load from cache even disable mod_expires


Test on this url http://getapple.net/phpbb/banners.js

It return 304, File not modified.

I have once enable plugin "mod_expires" and set up js to cache for 1 month.

But now i want to reset the rules. I try to comment this line

ExpiresByType application/javascript "access 1 month"

and then restart apache.

But the file still load from cache. (Response Header return 304 in Chrome Browser)

But after i run this

curl -I http://getapple.net/phpbb/banners.js

in command line, the result are

HTTP/1.1 200 OK
Date: Sun, 10 May 2015 14:51:59 GMT
Server: Apache/2.4.7 (Ubuntu)
Last-Modified: Sun, 10 May 2015 14:34:14 GMT
ETag: "9dd2-515bb27cf250a"
Accept-Ranges: bytes
Content-Length: 40402
Vary: Accept-Encoding
Content-Type: application/javascript

I don't know what i did wrong. Please suggest how to get the updated version of my file via url.

Thanks a lot.


Solution

  • When you send Expires header to browser, it will cache your response and only check for newer version after the expiration date has passed. Since browser won't check for newer version, changing your server settings won't affect browser's cached data. If you made some mistake in your script or there is an update, you can use query string to force browsers to ask for your script.

    Assume this is your current script:

    <script src="http://getapple.net/phpbb/banners.js" ></script>
    

    What you need to do:

    <script src="http://getapple.net/phpbb/banners.js?v=20150510" ></script>
    

    Since URL is not the same, browser will ask for the one with query string and your new settings will be applied!