473,326 Members | 2,337 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,326 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 2588
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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.