How to update cached .js files?

R

Robert Scheer

Hi.

I have two .js files that are used on several of my pages. I made some
changes in one of the files. When I call the pages, the old functions
are called because of the browser's cache. What is the best way to
update the browser's cache with the newer version of my .js file?

Thanks,
Robert Scheer
 
K

kaeli

Hi.

I have two .js files that are used on several of my pages. I made some
changes in one of the files. When I call the pages, the old functions
are called because of the browser's cache. What is the best way to
update the browser's cache with the newer version of my .js file?

Empty the cache (on some, control+alt+reload/refresh will work) or set
browser settings to check on every page view.

This is browser-dependent.

In IE, it's under tools->internet options. (IE calls them temporary
files)
In NN, it's under preferences somewhere.

--
--
~kaeli~
God was my co-pilot... but then we crashed in the mountains
and I had to eat him.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
 
R

Robert Scheer

Hi Kaeli.

I need to do it automatically. The site is on the internet and I think
it will be cumbersome to let my users clean the cache. Do I really
need to ask my users to clean the cache? Is it the only way?

Thanks,
Robert Scheer
 
K

kaeli

Hi Kaeli.

I need to do it automatically. The site is on the internet and I think
it will be cumbersome to let my users clean the cache. Do I really
need to ask my users to clean the cache? Is it the only way?

Basically, yes.

You have no real control over a user's cache (for security reasons,
actually). You can ask nicely in some instances with meta tags, but
IIRC, my settings can still prevent that from working.

I have had problems with Netscape 7.1 not clearing the cache (even
manually clearing it I still get old crap) with some sites (notably
http://www.newsnow.co.uk/). Still can't figure out if it's my settings,
their coding, or a bug...
(also, it may be a proxy issue if you use one - I do)

Expiring the file MAY help, but I'm not positive.
Here is a link to a caching tutorial.
http://www.mnot.net/cache_docs/


--
 
G

Grant Wagner

HikksNotAtHome said:
If they are getting cached .js files, how are you ensuring they get non-cached
html files?

And until you come up with a way to ensure they are not getting cached files,
yes, the only way is to have them clear the cache.

After you get it cleared up, the simplest way to ensure the file comes from the
server is to append the current date to the name of the js file as a parameter.
And then you are defeating the primary purpose of .js files and that is the
repeated download of the same code. (There are more reasons than that for .js
files but that seems to be the predominant use of them)

You can append a "version" or date information without defeating the point of
cached .js files.

<script type="text/javascript" src="file.js?v=200401151300"></script>

When file.js is modified, simply change the value of "v" to something else. If you
have access to server-side includes, this it's easy to update the occurrance on
every page that uses this file by simply putting the <script ...></script> tags in
an SSI.

If not, then you'll need a tool that does search and replace across multiple files.

--
| Grant Wagner <[email protected]>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtml_reference_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-developer/upgrade_2.html
 
T

Thomas 'PointedEars' Lahn

Robert said:
Hi Kaeli.

This is a public newsgroup, not private e-mail. [psf 7.21]
Do I really need to ask my users to clean the cache? Is it the only way?

Yes, it is, for my cache is *my* cache.

And please do not top-post.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,208
Latest member
RandallLay

Latest Threads

Top