Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Refresh Javascript Sources

Reply
Thread Tools

Refresh Javascript Sources

 
 
JamesBond
Guest
Posts: n/a
 
      11-20-2005
I am using a javascript in my html page which will be updated daily.
However, the javascript is getting cached by the browser and whenever
the user visits my html page, he is getting a cached copy of the
javascript though the javascript is updated.

Is there any way to force the browser not to cache this javascript?

 
Reply With Quote
 
 
 
 
Richard Cornford
Guest
Posts: n/a
 
      11-20-2005
JamesBond wrote:
> I am using a javascript in my html page which will be
> updated daily. However, the javascript is getting cached
> by the browser and whenever the user visits my html page,
> he is getting a cached copy of the javascript though the
> javascript is updated.
>
> Is there any way to force the browser not to cache this
> javascript?


That would be silly. You want the javascript cached as much as possible.
(You want everything cached as much as possible). If you are changing
the script on a daily bases you should send an HTTP Expires header than
tells the browser when the current version expires and then it should
check for a new version when the old one expires.

Alternatively you could put a (dummy) query string in the SRC attribute
for the javascript file and change that whenever you want a new version
recovered from the server. I.E. you might start with:-

SRC="someJsFile.js?V=1"

- and when you update the JS file change the references to:-

SRC="someJsFile.js?V=2"

- and the browser will not see its cached version as the resource in
question and it will have to get a new one from the server. That way the
file is still cached on the client whenever it is not changed.

Obviously going through an entire web site updating query stings is not
a good idea so this would be better done dynamically, with the version
number that is appended to the query string available as an application
wide variable. This works best for intermittent and unpredictable
updates, if you are genuinely updating daily then appropriate Expires
headers are a much better approach.

Richard.


 
Reply With Quote
 
 
 
 
JamesBond
Guest
Posts: n/a
 
      11-21-2005
Hi Richard,

Thanks for your reply. But, could you please let me know how I could
sent Expires header in a javascript. I am very new to this.

Thanks,
James.

 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      11-21-2005
JamesBond wrote:

> Thanks for your reply. But, could you please let me know how I could
> sent Expires header in a javascript. I am very new to this.


That header can only be set/sent from server-side, for example through
JScript in ASP. Googling for "iis response header expires" linked to
<URL:http://support.microsoft.com/kb/q234067/> as first hit.


PointedEars
 
Reply With Quote
 
JamesBond
Guest
Posts: n/a
 
      11-22-2005
Is it possible that I call a php page which returns javascript content
from the javascript tag as shown in the example below?
<script language="javascript" src="/js.php"></script>

In such a case, will the browser still cache it??

 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      11-22-2005
JamesBond wrote:

> Is it possible that I call a php page which returns javascript
> content from the javascript tag as shown in the example below?
> <script language="javascript" src="/js.php"></script>


Yes, however that should be

<script type="text/javascript" src="/js.php"></script>

See also news:

> In such a case, will the browser still cache it??


See <URL:http://www.mnot.net/cache_docs/>.


PointedEars
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
JSP: Session parameters vanish on refresh. How do I keep them on refresh? Per Magnus L?vold Java 1 10-08-2004 02:52 PM
How do i refresh a datagrid from a pop up window without having to refresh the whole page? Pkenty ASP .Net Web Controls 0 05-28-2004 07:06 AM
How to have multiple language sources in one project? Hamed ASP .Net 3 02-15-2004 03:27 PM
using refresh button on the menu bar to refresh two frames. Jawahar Rajan ASP General 1 10-01-2003 09:20 PM
Problem with refresh button breaking automatic refresh brian lanning ASP .Net 0 07-29-2003 07:57 PM



Advertisments