JRS: In article <95*************************@posting.google.com> , seen
in news:comp.lang.javascript, Attila <Th******************@hotmail.com>
posted at Fri, 16 Jan 2004 07:33:19 :-
My website stores JavaScript in .js files. From what I understand,
most web browsers cache .js files. My question is, if I make changes
to the file, how can I be sure that users will use the most recent
version of the JS file?
Untested :
every page has
<script type="text/javascript">
document.write(
'<script type="text/javascript" src="version.js?' +
new Date() + '"></scr'+'ipt>'
)
</script>
version.js is thus effectively uncached.
File version.js contains ONLY
var LatestVersion = 99 // update number as needed
Other pages contain, after as above,
<script type="text/javascript">
document.write(
'<script type="text/javascript" src="page45.js?' +
LatestVersion + '"></scr'+'ipt>'
)
</script>
ISTR that script can write script blocks, but the </script> must be
concealed.
Now, changing the contents of version.js effectively invalidates all
caches, although it does not flush the old stuff. ???
Naturally, you can have an array for LatestVersion, to control cacheing
of different groups of pages independently.
/Untested.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.