javascript caching control

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
howardr
Forum Newbie
Posts: 17
Joined: Mon Oct 31, 2005 1:33 pm

javascript caching control

Post 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
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Post 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...
howardr
Forum Newbie
Posts: 17
Joined: Mon Oct 31, 2005 1:33 pm

Post 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.
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Post by JellyFish »

I thought you meant have your src js file never cached?
User avatar
shoebappa
Forum Contributor
Posts: 158
Joined: Mon Jul 11, 2005 9:14 pm
Location: Norfolk, VA

Post 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).
Post Reply