Apache maintains older file versions

I am debugging js code on localhost and I need to prevent browser caching of files. I can't use a timestamp attached to the url as it removes the breakpoints of the chrome debugger.

Usually I don’t need to update the cache, but I do this all the time. This is a big problem because I searched elsewhere for errors. I added this code to apache a while ago:

<IfModule mod_headers.c> Header add Expires "Sun, 19 Nov 1978 05:00:00 GMT" Header add Cache-Control "no-store, no-cache, must-revalidate, post-check=0, pre-check=0" </IfModule> 

Can someone explain why Apache made a mistake for the file or provided some additions to the configuration code that could fix this once and for all?

Headings using the solution below:

 <IfModule mod_expires.c> expiresActive On ExpiresDefault "access plus 1 seconds" ExpiresByType text/html "access plus 1 seconds" ExpiresByType text/javascript "access plus 1 seconds" ExpiresByType application/x-javascript "access plus 1 seconds" </IfModule> http://localhost/static/images/%d0%9a%d0%be%d0%bf%d0%b8%d1%8f%20logo_inner.png GET /static/images/%d0%9a%d0%be%d0%bf%d0%b8%d1%8f%20logo_inner.png HTTP/1.1 Host: localhost User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:16.0) Gecko/20100101 Firefox/16.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate Connection: keep-alive Referer: http://localhost/static/images/ Cache-Control: max-age=0 HTTP/1.1 200 OK Date: Sun, 23 Dec 2012 19:33:20 GMT Server: Apache/2.2.22 (Ubuntu) Last-Modified: Thu, 28 Jun 2012 17:32:51 GMT Etag: "b3c27-f1f-4c38bb88d96c0" Accept-Ranges: bytes Content-Length: 3871 Expires: Sun, 19 Nov 1978 05:00:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Keep-Alive: timeout=15, max=99 Connection: Keep-Alive Content-Type: image/png HTTP/1.1 200 OK Date: Sun, 23 Dec 2012 19:33:54 GMT Server: Apache/2.2.22 (Ubuntu) Last-Modified: Thu, 28 Jun 2012 17:32:51 GMT Etag: "b3c27-f1f-4c38bb88d96c0" Accept-Ranges: bytes Content-Length: 3871 Cache-Control: max-age=1 Expires: Sun, 23 Dec 2012 19:33:55 GMT Keep-Alive: timeout=15, max=100 Connection: Keep-Alive Content-Type: image/png The second request: http://localhost/static/images/%d0%9a%d0%be%d0%bf%d0%b8%d1%8f%20logo_inner.png GET /static/images/%d0%9a%d0%be%d0%bf%d0%b8%d1%8f%20logo_inner.png HTTP/1.1 Host: localhost User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:16.0) Gecko/20100101 Firefox/16.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate Connection: keep-alive Referer: http://localhost/static/images/ If-Modified-Since: Thu, 28 Jun 2012 17:32:51 GMT If-None-Match: "b3c27-f1f-4c38bb88d96c0" Cache-Control: max-age=0 HTTP/1.1 304 Not Modified Date: Sun, 23 Dec 2012 19:34:58 GMT Server: Apache/2.2.22 (Ubuntu) Connection: Keep-Alive Keep-Alive: timeout=15, max=99 Etag: "b3c27-f1f-4c38bb88d96c0" Expires: Sun, 23 Dec 2012 19:34:59 GMT Cache-Control: max-age=1 
+4
source share
2 answers

When delivering static files, Apache sends an ETag header, which is a bit of a file checksum. The browser will cache the file and remember the ETag, which is sent with the following request.

If the file changes the browser, then the ETag should be different, and the web server should resend, when etag is equal, the web server will respond with 304 Not Modified . The ETag engine has higher priority than other cache headers.

To disable etags, you can use apaches

 FileETag None 

http://httpd.apache.org/docs/current/en/mod/core.html#fileetag

Wikipedia has a good article on the Etag header http://en.wikipedia.org/wiki/HTTP_ETag

Edit

It must be a waterproof configuration.

 FileETag None <ifModule mod_headers.c> Header unset ETag Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate" Header set Pragma "no-cache" Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT" </ifModule> 

Remember that a server restart is required to change the configuration.

 sudo /etc/init.d/httpd restart 

EDIT2

Wrap the files. Run the configuration to disable caching for specific file extensions only.

 <filesMatch ".(php|js|css)$"> FileETag None [..] </filesMatch> 
+10
source

If I understand your requirement correctly, you want the web browser to not remember anything about the web page you are accessing, and your Apache web server should treat it as a new page request. You can enable mod_expires and mod_headers first, I use ubuntu, so mine was

 a2enmod headers && a2enmod expires && service apache2 restart 

than you want to add below code for minimal cache control,

 <IfModule mod_expires.c> expiresActive On ExpiresDefault "access plus 1 seconds" ExpiresByType text/html "access plus 1 seconds" ExpiresByType text/javascript "access plus 1 seconds" ExpiresByType application/x-javascript "access plus 1 seconds" </IfModule> 

If you are using firefox, you can verify this by installing / running the Live Http header Plugin, or if you are using linux / unix, you can run this request with curl -v your_url

+1
source

All Articles