473,386 Members | 1,609 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Force page load to always reload external JS library

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
4 12738
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
"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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: SpaceCowboy | last post by:
To begin, I'm using JBuilder9 under J2ME and MIDP 1.0. I'm trying to use an external library. I can get my code to compile, but I can't get the library code working on the emulator. I'm...
3
by: BlackSabbath | last post by:
Hi, all I try to explain (with my #@^^~ english..., sorry...) : I have a page e.g. Product125.htm I would that, if a guy call http:\\www.MySite.htm\Products\product125.htm to force the...
1
by: WFB | last post by:
Hi, I have a base class from which all of my pages derive (ABCBasePage). For example, ABCCustomerSelect Inherits ABCPasePage. I would now like to have ABCPocketSelect which should inherit from...
15
by: H00ner | last post by:
Hello All Hope you can help Been pulling my hair out about a popup problem in ASP.NET. One of the forms i wrote requires the user to select a product from a list in a popup web form. the...
8
by: MaryA | last post by:
I have an aspx page that loads twice inspite of using the IsPostBack i removed all controls from the page and still the page_load event is called twice I appriciate any help coz i have lost...
6
by: ¿ Mahesh Kumar | last post by:
Hi groups, Control name : ListboxID (lstCertification), selection mode=mutliselect. On Pageload i'm assinging string lstSplit="1/3/6/8" of the previously selected listindex id's. Now on the...
2
by: Zeba | last post by:
Hi ! How do I distinguish a page reload event ( i mean a page_load due to some clicks, etc. which dont cause a postback) from a page load event ( the first time the page loads) ?? Thanks !
2
by: Mugs321 | last post by:
Hey all, I'm developing an online testing system. If there are multiple tests, there are admin-defined breaks between each test. I've used a modal window (all users are using IE, 100%...
2
by: RobertTheProgrammer | last post by:
Okay, here's another one for you. Hopefully I can articulate my problem well enough... I've got a GridView (with C# code behind) that is having some page load issues. Users can enter and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.