473,395 Members | 1,791 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,395 software developers and data experts.

FAQ Topic - How do I force a reload from the server/prevent caching?

-----------------------------------------------------------------------
FAQ Topic - How do I force a reload from the server/prevent caching?
-----------------------------------------------------------------------

To reload a page, use location.reload(). However, this depends
upon the cache headers that your server sends. To change this,
you need to alter the server configuration. A quick fix on the
client is to change the page URI so that it contains a unique
element, such as the current time. For example:
« location.replace(location.href+'?d='+new Date().valueOf()) »
If the location.href already contains a Query String, use:
« location.replace(location.href+'&d='+new Date().valueOf()) »

http://www.mnot.net/cache_docs/

http://docs.sun.com/source/816-6408-10/date.htm
===
Postings such as this are automatically sent once a day. Their
goal is to answer repeated questions, and to offer the content to
the community for continuous evaluation/improvement. The complete
comp.lang.javascript FAQ is at http://www.jibbering.com/faq/.
The FAQ workers are a group of volunteers.

Oct 26 '06 #1
5 2595
FAQ server wrote on 27 okt 2006 in comp.lang.javascript:
-----------------------------------------------------------------------
FAQ Topic - How do I force a reload from the server/prevent caching?
-----------------------------------------------------------------------

To reload a page, use location.reload(). However, this depends
upon the cache headers that your server sends. To change this,
you need to alter the server configuration. A quick fix on the
client is to change the page URI so that it contains a unique
element, such as the current time. For example:
® location.replace(location.href+'?d='+new Date().valueOf()) ¯
new Date().valueOf().toString(36)

will give a more compact [8 against 13 chars] equally functional string,
[non repeating if the time between requests is of reasonable length.]

If the location.href already contains a Query String, use:
® location.replace(location.href+'&d='+new Date().valueOf()) ¯
This is a bad advice, since a d=.. could be already present or
it's absense to be tested.

Use:

location.replace(location.href+'&new Date().valueOf())

or as shown above:

location.replace(location.href+'&new Date().valueOf().toString(36))

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Oct 27 '06 #2
Idea:
location.href = location.href + '&' + Math.random();

Evertjan. wrote:
FAQ server wrote on 27 okt 2006 in comp.lang.javascript:
-----------------------------------------------------------------------
FAQ Topic - How do I force a reload from the server/prevent caching?
-----------------------------------------------------------------------

To reload a page, use location.reload(). However, this depends
upon the cache headers that your server sends. To change this,
you need to alter the server configuration. A quick fix on the
client is to change the page URI so that it contains a unique
element, such as the current time. For example:
® location.replace(location.href+'?d='+new Date().valueOf()) ¯

new Date().valueOf().toString(36)

will give a more compact [8 against 13 chars] equally functional string,
[non repeating if the time between requests is of reasonable length.]

If the location.href already contains a Query String, use:
® location.replace(location.href+'&d='+new Date().valueOf()) ¯

This is a bad advice, since a d=.. could be already present or
it's absense to be tested.

Use:

location.replace(location.href+'&new Date().valueOf())

or as shown above:

location.replace(location.href+'&new Date().valueOf().toString(36))

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Oct 27 '06 #3
vifito wrote:
Idea:
location.href = location.href + '&' + Math.random();
Two consecutive random numbers may be the same number, and numbers
certainly may re-occur within a session, or the expiry period of a cached
document. Time values have the advantage of being a non-repeating
sequence so they will all be unique if requested less frequently than the
rate at which time is incremented on OS in use.

Richard.
Oct 27 '06 #4

FAQ server wrote:
-----------------------------------------------------------------------
FAQ Topic - How do I force a reload from the server/prevent caching?
-----------------------------------------------------------------------

To reload a page, use location.reload(). However, this depends
upon the cache headers that your server sends.
The option of "location.reload(true)" should perhaps be mentioned.
Without the parameter, you can get what's in the cache. The "true"
is supposed to force a real reload.

Kev

Oct 27 '06 #5
In message <Xn********************@194.109.133.242>, Fri, 27 Oct 2006
08:05:08, Evertjan. <ex**************@interxnl.netwrites
>
new Date().valueOf().toString(36)

will give a more compact [8 against 13 chars] equally functional
string, [non repeating if the time between requests is of reasonable
length.]
And

(+new Date()).toString(36)

gives the same with less code.
I suggest rewording "of reasonable length", since at first I took it to
mean "not too long" - and there the limit would be over 275,000 years.

AFAIK, a nominal 55 ms will always be long enough for the time to have
changed.

With the sort of algorithm which one expects to be used, Math.Random()
will repeat only after 2^32, 2^53, or 2^64 calls. Conversions to String
*may* repeat more often on the average, and possibly sometimes quite
soon. It is probably initialised from the clock, either per-page or per
browser instance. That gets complex.

<URL:http://www.merlyn.demon.co.uk/js-randm.htm#MRshould show the
resolution of Math.random(); but think about the code.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Oct 27 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Martin | last post by:
This is probably more of an HTML question than PHP. Perhaps someone here can answer or point me to a proper newsgroup. How can I force the browser to reload an image from the server? I have a...
3
by: ghostwolf | last post by:
Hi, I'm new to ASP.NET. If the web page is running in server-side, how can I reload the particular section of the web page instead of the whole page? Say, I've separated the web page into several...
1
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I force a reload from the server/prevent caching?...
1
by: Rob | last post by:
I know this is an old one, considering how many posts I found on it but I just wondered if any best practises had popped up recently, especially as Ajax has increased JavaScript and DHTML's...
1
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I force a reload from the server/prevent caching?...
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: 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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.