NodeGuy / server-date

Make the server's clock available in the browser.
http://www.nodeguy.com/serverdate/
Mozilla Public License 2.0
193 stars 53 forks source link

noCache string not entirely reliable #32

Closed hq9000 closed 7 years ago

hq9000 commented 7 years ago

it's now just a client's timestamp. Right? I can imagine several clients with mismatched clocks doing the same request with the same parameter in astronomically different moments. Then, if it's not a browser cache we're talking about, or, rather some public cache or something, then the second, third... requests might get outdated cached response.

Wouldn't it be more reliable to add some randomness to this?

like so: // Ask the server for another copy of ServerDate.js but specify a unique number on the URL querystring // so that we don't get the browser cached Javascript file request.open("HEAD", URL + "?noCache=" + Date.now() + parseInt(Math.random()*100000));

hq9000 commented 7 years ago

and another thing, when we load the ServerData.js initially (in the html code) we might want to add some anti-caching parameters (say, provided by an assets management system), like ?v=5

then, when the lib generates sample requests for itself it'd generage something like ServerData.js?v=5?noCache=123456 which is not a valid URL (two question marks).

I've changed it in our copy to add noCache through "&" but some generic solution would be nice to have too )

NodeGuy commented 7 years ago

I'm open to your suggestions and would welcome a pull request.

hq9000 commented 7 years ago

https://github.com/NodeGuy/ServerDate/pull/33

I guess this is it.

NodeGuy commented 7 years ago

Merged.