From: FAQ server on
-----------------------------------------------------------------------
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


The complete comp.lang.javascript FAQ is at
http://jibbering.com/faq/

--

The sendings of these daily posts are proficiently hosted
by http://www.pair.com.

From: nick on
On May 5, 7:26 pm, David Mark <dmark.cins...(a)gmail.com> wrote:
> 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. 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()) `
>
> The valueOf calls would seem superfluous.

the valueOf calls give the numeric representation instead of the
string representation when used with + as concatenation operator. It's
more precise and it doesn't contain spaces.

for (i=10;i--;) console.log(new Date(), '...', new Date().valueOf())
Wed May 05 2010 19:50:46 GMT-0400 (EDT) "..." 1273103446197
Wed May 05 2010 19:50:46 GMT-0400 (EDT) "..." 1273103446199
Wed May 05 2010 19:50:46 GMT-0400 (EDT) "..." 1273103446199
Wed May 05 2010 19:50:46 GMT-0400 (EDT) "..." 1273103446199
Wed May 05 2010 19:50:46 GMT-0400 (EDT) "..." 1273103446200
Wed May 05 2010 19:50:46 GMT-0400 (EDT) "..." 1273103446200
Wed May 05 2010 19:50:46 GMT-0400 (EDT) "..." 1273103446201
Wed May 05 2010 19:50:46 GMT-0400 (EDT) "..." 1273103446201
Wed May 05 2010 19:50:46 GMT-0400 (EDT) "..." 1273103446202
Wed May 05 2010 19:50:46 GMT-0400 (EDT) "..." 1273103446202
From: David Mark on
nick wrote:
> On May 5, 7:26 pm, David Mark <dmark.cins...(a)gmail.com> wrote:
>> 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. 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()) `
>> The valueOf calls would seem superfluous.
>
> the valueOf calls give the numeric representation instead of the
> string representation when used with + as concatenation operator. It's
> more precise and it doesn't contain spaces.

The unary plus operator does the same thing.

>
> for (i=10;i--;) console.log(new Date(), '...', new Date().valueOf())

Add a "+" before "new Date()".
From: David Mark on
David Mark wrote:
> nick wrote:
>> On May 5, 7:26 pm, David Mark <dmark.cins...(a)gmail.com> wrote:
>>> 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. 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()) `
>>> The valueOf calls would seem superfluous.
>> the valueOf calls give the numeric representation instead of the
>> string representation when used with + as concatenation operator. It's
>> more precise and it doesn't contain spaces.
>
> The unary plus operator does the same thing.
>
>> for (i=10;i--;) console.log(new Date(), '...', new Date().valueOf())
>
> Add a "+" before "new Date()".

NM. I misread the original (I blame lousy spacing). :)
From: Garrett Smith on
nick wrote:
> On May 5, 7:26 pm, David Mark <dmark.cins...(a)gmail.com> wrote:
>> 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. 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()) `
>> The valueOf calls would seem superfluous.
>
> the valueOf calls give the numeric representation instead of the
> string representation when used with + as concatenation operator. It's
> more precise and it doesn't contain spaces.
>
Nor any other characters that need encoding.
--
Garrett
comp.lang.javascript FAQ: http://jibbering.com/faq/