By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,446 Members | 3,090 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,446 IT Pros & Developers. It's quick & easy.

Force page load to always reload external JS library

P: n/a
Sorry if this is borderline JS vs. HTML. I ask here as the
success/failure if the resulting JS is key.

I've a small external .JS library that allows a non code-savvy user to
occasionally update a list of values that are read as a JS array and
used to populate the <option>s of a <select> in the calling page's form.

Anyway, is there a way by which I can ensure, regardless of the user's
browser settings, that the JS library is not used from cache but re-read
each time, to ensure the up to date list is used?

If not, I might as well put the JS array code back in the calling page,
especially as the split is for ease of use by the page's owner, albeit
with increased change of editing errors. A database solution, etc., is
inappropriate here.

TIA,

Mark
Jul 23 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Mark Anderson wrote:
Sorry if this is borderline JS vs. HTML. I ask here as the
success/failure if the resulting JS is key.

I've a small external .JS library that allows a non code-savvy user to
occasionally update a list of values that are read as a JS array and
used to populate the <option>s of a <select> in the calling page's form.

Anyway, is there a way by which I can ensure, regardless of the user's
browser settings, that the JS library is not used from cache but re-read
each time, to ensure the up to date list is used?

If not, I might as well put the JS array code back in the calling page,
especially as the split is for ease of use by the page's owner, albeit
with increased change of editing errors. A database solution, etc., is
inappropriate here.


You dynamically create the script tag with a unique paramater to it.

<script type="text/javascript">
document.write('<script type="text/javascript"
src="myFile.js?' + new Date().getTime() + '">
<\/script>');
</script>

It is split across lines for readability only.
The idea is that the parameter in the file name should always be unique
since you are appending the current time to the filename. Since the
filename is unique, it can not be retrieved from the cache.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Jul 23 '05 #2

P: n/a
"Randy Webb" <Hi************@aol.com> wrote in message
news:ff********************@comcast.com...
You dynamically create the script tag with a unique paramater to it.

<script type="text/javascript">
document.write('<script type="text/javascript"
src="myFile.js?' + new Date().getTime() + '">
<\/script>');
</script>

It is split across lines for readability only.
The idea is that the parameter in the file name should always be
unique since you are appending the current time to the filename. Since
the filename is unique, it can not be retrieved from the cache.


I get the idea but it doesn't work as the browser can't find the
referenced JS file as its filename is missing the date info added by the
dynamic reference. I've tested the solution - IE & Firefox both fail.

I used (lines may wrap):
~~~HTM~~~
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script type="text/javascript">
document.write('<script type="text/javascript" src="myFile.js?' + new
Date().getTime() + '"><\/script>');
</script>
</head>
<body>
Text Line 1 in HTM file source<br><br>
<script type="text/javascript">
writeMe();
</script>
</body>
</html>
~~~End HTM~~~
~~~JS~~~
function writeMe(){
document.write('Text Line 1 from JS file source<br><br>Text Line 2
from JS file source.')
}
~~~End JS~~~

Thanks,

Mark
Jul 23 '05 #3

P: n/a
Lee
Mark Anderson said:

"Randy Webb" <Hi************@aol.com> wrote in message
news:ff********************@comcast.com...
You dynamically create the script tag with a unique paramater to it.

<script type="text/javascript">
document.write('<script type="text/javascript"
src="myFile.js?' + new Date().getTime() + '">
<\/script>');
</script>

It is split across lines for readability only.
The idea is that the parameter in the file name should always be
unique since you are appending the current time to the filename. Since
the filename is unique, it can not be retrieved from the cache.


I get the idea but it doesn't work as the browser can't find the
referenced JS file as its filename is missing the date info added by the
dynamic reference. I've tested the solution - IE & Firefox both fail.

I used (lines may wrap):
~~~HTM~~~
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script type="text/javascript">
document.write('<script type="text/javascript" src="myFile.js?' + new
Date().getTime() + '"><\/script>');


The server will ignore the "?" and anything following it when it looks
for the .js file. If it's failing to find it, it's because you don't
have a file named "myFile.js" in the base directory.

Jul 23 '05 #4

P: n/a
"Lee" <RE**************@cox.net> wrote in message
news:d0*********@drn.newsguy.com...
Mark Anderson said:
The server will ignore the "?" and anything following it when it looks
for the .js file. If it's failing to find it, it's because you don't
have a file named "myFile.js" in the base directory.


Yes, apologies - the problem was a naming error. All working!

Thanks everyone,

Mark
Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.