UPDATE 2
I discovered the answer but I'm not sure why it's required and how to change this behavior in Apache.
If I unlink
(i.e. delete) the XML file first and then recreate it (instead of just writing over it), then both browsers see the fresh version!
//This causes a fresh version
unlink( $xmlFileLocation );
//Now creating it will result in a non-cached version being sent
$f = fopen( $xmlFileLocation, "wb" );
fwrite(, $xmlFileLocation, $xml );
fclose( $xmlFileLocation );
If I do the above without unlink
, then it gets changed and the modified date is updated on disk, but Apache continues to serve the old version!! Why?
UPDATE 1 - problem still happening despite mod_headers enabled!
I thought I needed to enable the module mod_headers.
sudo a2enmod headers
but both Chrome and Firefox still appear to be getting old versions of the XML file!
What could be causing Apache to continue to serve the old version? (Clearing the browser cache did not help and the file on disk IS different from what gets seen in both browsers)
Original POST
I'm trying to stop the browser from caching the XML files I'm serving up but it's not working. When I view the file on the computer itself, it shows it is updated, but in the browser (Chrome and Firefox) it shows as the old version!
I am certain my htaccess which is located in the XML file folder is working (I tested by changing it to deny from all
and it correctly showed a "Forbidden"
response).
.htaccess
<FilesMatch ".(xml)$">
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>
</FilesMatch>
This does not stop the caching! What else can I do?
EDIT I'm not sure, but I think Apache might be caching it server-side! How would I diagnose and stop that?
I think that's the case due to Chrome showing the request headers:
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:no-cache
Connection:keep-alive
Host:mywebsite.com
Pragma:no-cache
yet it still shows the cached version!