views:

87

answers:

4

Last Thursday we just released a new version of our website. The big change was we converted from Prototype to jQuery. This of course included lots of changes to referenced javascript files. There were new css file changes as well. Unfortunately, many of our customers aren't seeing the changes. I even had one customer clear their browser cache, press F5 and download the js file directly. He still was getting the old version.

What methods do we have to notify all of the participants (browser, proxy servers, etc) of the changes to our files?

BTW, many of our customers are Fortune 500 companies. They use IE 6 and often are behind a proxy server.

We use Tomcat 6 and Apache 2.

+1  A: 

I had a similar problem. In the end I "solved" it by sending http headers with every page to say the content had expired and force a renewal of the page. Not a very elegant solution though.

In PHP this was:

header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past

Not sure about Tomcat though.

me_here
The question was asking about a Tomcat setup, so PHP isn't extremely relevant, but the HTTP header values can also be set in Java.
Ben S
+2  A: 

For Tomcat, when you deploy make sure you delete everything in the work/Catalina/localhost directory prior to restarting. This is a cache directory for tomcat. Also adding the headers in your servlet/JSP as stated by me_here can be helpful.

jconlin
I always remove the work directory when I release. Most users are seeing the right file, so I know it can't be the work directory.
Trevor Allred
+2  A: 

If the proxy servers are caching your site, there's very little you can do. You can try adding CACHE-CONTROL and PRAGMA:NO-CACHE headers to your pages.

You should also try replicating the problem with as little between you and the server as possible. I've had problems with Tomcat holding onto files in its 'work' cache, so be sure to delete that.

Carl
We actually had a problem with the proxy servers holding onto our html files. But I added ServletActionContext.getResponse().setHeader("Cache-Control", "private, max-age=0");to an an interceptor. That solved the problem with the servers caching those files. But the js, css, and images still get cached sometimes.
Trevor Allred
+2  A: 

I noticed that StackOverflow uses version numbers on their files

http://sstatic.net/so/js/question.js?v=5207

So I tried this on our site and it seems to be working. The one user who had an especially stubborn browser saw the results immediately after the change.

The thing I like about this is that it's really not that difficult for us to implement and it still allows the browsers and proxies to cache the files that don't change a lot.

Trevor Allred
For an even more flexible variation, just appending the Unix last-modified timestamp of the script file to the source attribute, e.g. "script.js?NNNNNNNNNNNNNNNNN" would do it, and it means the cache miss happens whenever the file changes. In production, of course, this will happen when a new release does.
Rob