From: nick on
On May 5, 7:43 pm, David Mark <dmark.cins...(a)gmail.com> wrote:
> 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).  :)

Point taken, though. This works in my browser:

location.replace(location.href + '?d=' + +new Date())

This might be safer?

location.replace(location.href + '?d=' + (+new Date()))

From: David Mark on
nick wrote:
> On May 5, 7:43 pm, David Mark <dmark.cins...(a)gmail.com> wrote:
>> 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). :)
>
> Point taken, though. This works in my browser:
>
> location.replace(location.href + '?d=' + +new Date())
>
> This might be safer?
>
> location.replace(location.href + '?d=' + (+new Date()))
>

I don't think it is safer, but it is certainly advisable for readability.