2
votes

I'm having a lot of trouble getting Chrome and Firefox to clear the cached version of a document that I have being served via mod_rewrite. That is to say, I can't get either Chrome or Firefox to go back to the server to get the modified version.

Here is what it looks like in the network panel of Chrome Developer Tools:

Headers according to Chrome

When I make the request from the command line with curl to look at the headers my server is sending back, here's what I get:

enter image description here

/Dashboard is rewritten to /index.html using this rewrite rule:

RewriteBase / RewriteCond %{REQUEST_FILENAME} !-l RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule .* index.html [L,QSA]

I have tried just about everything I can think of to get this document out of Chrome's cache, to no avail. Any help is appreciated.

Update: Here's another screenshot of the page when in incognito mode. I have caching disabled with dev tools open, I cleared the cache, and incognito mode is active. I'm still getting this first page from cache.

enter image description here

1
Have you tried a hard refresh (e.g., Ctrl + F5)? - elixenide
Yep. Tried that. Tried clearing history through the menu. Tried clearing cache by right clicking on "Dashboard" in the network tab and selecting clear browser cache. Went into ~/.cache/ and deleted the entire google-chrome directory (I'm on Linux). It's still pulling it from cache. I'm completely flummoxed. - Erik Mitchell
I'm testing it by putting a 5px border on the <body> of that page, and changing the color. My current cached version for "Dashboard" has no border. Another route that works in my applicaton is "Messages". That has a red border. "Dashboardfoo" has a blue border. The browser has cached different versions of index.html for each one of those URLs, and I can't get it to clear any of them. - Erik Mitchell

1 Answers

0
votes

Here's what it was: I'm using a "manifest" file as described here:

https://developer.mozilla.org/en-US/docs/Web/HTML/Using_the_application_cache

In my build I have a new VERSION and BUILD line being populated with a git commit id and build number, respectively, which I get from Jenkins.

However, I was looking at local builds, and the way I had it set up this file was getting "undefined" written for version and build on every build, so the contents of the file weren't changing.

The browser could see that the file wasn't changing, so it had no reason to think it had an outdated version of index.html.

I updated my grunt build to put in a timestamp when the Jenkins environment variables aren't there, and that fixed the problem -- for the most part. Now, when I load my application, the cached version of index.html is invalidated once the browser sees that my manifest has changed. The problem is I'm looking at a stale version of index.html now, so my entire session will be on the outdated version of index.html.

When I refresh, I then get the new version of index.html.

Plan is to put in a javascript function and GET my manifest file, pull the version, and store that in a cookie. Then on page load I'll compare that to what's already in the cookie, and if they don't match (new version of applicatoin), I'll to a top.location.reload() to get the newest index.html.