Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

javascript won't refresh after changes

Status
Not open for further replies.

manjoufna

Programmer
Sep 7, 2001
9
0
0
US
I'm running a Perl CGI script that uses a javascript external .js file. When I make a change to the .js file, the changes won't take effect unless I exit the browser (IE) completely and come back in. Using the refresh button on the browser or entering the URL won't do it. Changes to the Perl CGI script will take effect without having to exit the browser. Has anyone else ever experienced this?

Thanks,
Margaret
 
You mean a server-side script changes everytime you refresh the page, and a client-side script changes everytime you start the browser?

That is normal behaviour for any server-side script, be it CGI, SHTML, PHP, ASP etc. because those pages are likely to change - the may show the current time, for example :)

Client-side scripts are considered static. Just like a HTML file or image, it is anticipated that they will not likely to change frequently.

You can edit the MSIE/Internet Options to behave differently - i.e. check every time you request any document. I had used this settings but it can cause havock for some scripts so don't recommend it.

You can give the *.JS a *.SHTML extension or something like that - this will waste a little server CPU time, but the web browser will treat it as a dynamic document and re-request every time you refresh. It will also treat it as a .JS file because that's what it had been told the file is in the HTML markup <SCRIPT SRC=&quot;...

You may also be able to get your web server to change the HTTP headers associated with that .JS file which would be the optimal solution but that would require understanding the .htaccess scripting for your server and that's something I have very little knowledge of :)

Wow! Didn't think I was going to write that much.

Hope you found this text helpful :)
 
You may also be able to get away with renaming .JS to .JS?

This could, feasably, trick the browser into thinking the http_request was for a dynamic page but I haven't tested it.

Sorry for the poor grammar in my previous post. I must have been thinking more than one thing simultanously :p
 
Urk! I didn't mean that. I meant replacing .JS with .JS? in the <SCRIPT SRC='...'></SCRIPT>

Really bugs me that these forums lack an edit option :(
 

Doesn't &quot;Ctrl + f5&quot; force a refresh in IE too?
 
Thank you both for responding so quickly and for your information.
The info about client-side scripts vs. server-side scripts was helpful.

I did try the js? thing and that didn't seem to work.
The Control F5 appears to behave just like clicking the REFRESH button.

I've taken a different approach to my programming and don't need the .js refresh right now (Mostof my changes are going to be in the Perl CGI script), but if I do, I will try the remaining solutions you've offered.

Thanks again!
Margaret
 
Renaming the .JS to .SHTML does work. The project I'm working on is for people who cannot host server-side scripts.

This posed a problem because I needed an accurate source of time for that script - and the client time may be way off :(

The solution:

<SCRIPT SRC=&quot;
time.shtml is re-requested every time the page loads, and as you can see it's a javascript-ssi hybrid but there don't need to be any SSI directives to have the desired effect.

var time = '<!--#echo var=&quot;TIME_GMT&quot; -->';

Now the client-side script has a source of time and everything works perfectly. Point being, I'm sure that renaming to .SHTML would solve your problem also :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top