Page 1 of 1

javascript caching control

Posted: Tue Oct 24, 2006 8:51 pm
by howardr
i work for an internet startup company, and over the last 9 months we have been increasingly creating a more rich interface using javascipt. Today we came across a weird situation where some of our javascipt files would not become uncached. I changed our incude path from

Code: Select all

<script type="text/javascipt" language="javascript" src="/scripts/search.js" />

to

<script type="text/javascipt" language="javascript" src="/scripts/search.js?1" />
this fixed our problem.

Has anyone impleted a system that does this automatically when a js file is changed?

i got this idea from facebook's website, and a number of other websites i have noticed are doing something like this

Posted: Tue Oct 24, 2006 9:10 pm
by JellyFish
I got this by googling image cache (Boo Yah!) and using it for my speed tester. I used the numbers of the minute, second and milliseconds of the current time for the src's value (e.g. /scripts/search.js?10:19:234). If you don't know what I mean by it check the source of my Speed Tester...

Posted: Tue Oct 24, 2006 10:42 pm
by howardr
i want normal caching on because our js doest change all that often, but when it does i want to make sure everyone downloads it. i wondering if anyone has come u with a solution.

For example, something makes a md5 hash of every javascipt and if it changes, update the number on the end

Code: Select all

/scripts/search.js?d8ej92jd0
would become

Code: Select all

/scripts/search.js?h38fh28d
an automated way, instead of doing it by hand. if you want to take a look at the page i am talking about, goto http://www.uship.com/find_shipments.aspx. today we updated the js, but many of our users didnt not get the download and it screwed everything up.

Posted: Wed Oct 25, 2006 1:53 am
by JellyFish
I thought you meant have your src js file never cached?

Posted: Wed Oct 25, 2006 3:01 am
by shoebappa
Couldn't you append the file modified date of the js file (or md5 hash or base64 encoded of the modified date) in the same manner.

I've also seen the problem on some cache settings where it would cache the ajax content (I was using a session so the filename was always the same, but content returned should have been different, but wasn't being updated) and added a timestamp to those requests as well (current time from javascript not modified).