[Javascript] Cache prevention with a changing query string?

Rees, Mark (TWIi London) mrees at twii.net
Wed Jul 4 04:16:33 CDT 2001


Hello

If you change the querystring of a page to something which isn't in the
cache, your browser (ie4+, netscape4+ at least) will request it from the
server again - you can test that easily enough for yourself.

if you're in a shop environment you could use a session ID for the same
purpose (if you're using sessions of course) as they are pretty much unique
as well (at least in ASP).

Mark

-----Original Message-----
From: Rodney Myers [mailto:rodney at aflyingstart.net]
Sent: 04 July 2001 10:04
To: Javascript List
Subject: [Javascript] Cache prevention with a changing query string?


In comp.lang.javascript someone recommended a link like this to prevent
a page coming from cache.

The idea is to add a different query string every time the page is
called:

<p><a href="test.html"
  onclick="document.location.href='test.html?cCache=' + (new
 Date()).valueOf();return false;">link text</a></p>


Being a lazy person who prefers not to write things twice if once will
do, I would prefer to write something like:

<p><a href="test.html"
  onclick="document.location.href=this.href+'?cCache=' + (new
 Date()).valueOf();return false;">link text using this.href</a></p>

 Where this.href removes the need to repeat the page name.

 The contributor, whose original message I do not have, commented that
having a normal href property in the link would enable the link to work
with javacript off (though without the cache bypassing bonus).

 Does anyone have positive or negative expereince of working with such
anti cache devices?

 Assuming it does work, I would then work on adapting the date related
query string so that (for example) the query string would not change
during a day, so the page could come from cache during any given
shopping session.


 TIA

 Rodney

--
Shop at ssistant Add-ons and Developer Workshops
http://www.aflyingstart.net/addons/

Enquiries regarding Shop at ssistant Classic training :
Call 01256 880770

Rodney Myers
Based in Oxford, England
Technical Director, Shop at ssistant eCommerce Solutions



_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
http://www.LaTech.edu/mailman/listinfo/javascript




More information about the Javascript mailing list