Aamir Ghanchi wrote:
Hi,
Is there a way to force the browser to use the fresh script from the
website instead of reading the cached .js file. I have the same
question for the HTML code for that matter. Any meta tag, attribute,
that will make the browser to get the updated page from the webserver
instead of what was cached.
Depending on how often your external JavaScript content changes, you can
do one of two things:
1) <script type="text/javascript"
src="myfile.js?v=200407081320"></script>
Then simply modify the value of the [v]ersion when "myfile.js" changes.
If you use "myfile.js" in multiple places, put the above code into
another file and server-side #include it in the pages you need. When
"myfile.js" changes, you upload it, modify the SSI that includes the
above syntax and upload it.
2) <script type="text/javascript">
document.write(
'<script type="text/javascript" src="myfile.js?v=' +
(new Date()).getTime() +
'><\/script>'
);
</script>
(or you can use server-side code to do the same thing)
This will result in "myfile.js" being downloaded with each visit to the
page, which sort of negates the benefit of using an external JavaScript
file.
I use the first concept a lot, an external JS file with a SSI to include
it on pages. It is the easiest to maintain and guarantees everyone gets a
fresh copy only when I actually change something.
You can also control caching behaviour from your server: <url:
http://www.mnot.net/cache_docs/#CONTROL />
--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ -
http://jibbering.com/faq