Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detecting Cache 1

Status
Not open for further replies.

duckiebear

Programmer
May 25, 2004
32
0
0
US
Upon loading the webpage, I'm looking for a way to detect the user's browser cache setting, and if the cache is turned on, send the user a message. Does anyone know how I can detect this information?

Alternatively, I'd like to set the user's cache to expire immediately upon loading the page. I am not sure how this is done.
 

Although I've not tried this, it sounds plausible enough - but will require both client-side and server-side code. It also requires that the server-side page is on the same domain as the pages running this cache check.

Server-side, you would have to have a smart page. The job of this page is to serve different content each time it is loaded... a UUID / GUID, etc. Or even the time and date with msecs... whatever - as long as it is guaranteed to always be unique.

Client-side, you would have an iframe on your page, initially with no source. Programatically, you could set the source of the iframe to the page that generates random content. You would then grab that content, and store it in a variable (this is why the pages need to be on the same domain - security restrictions would apply otherwise).

Then, set the source of the page again, and grab the content that is delivered back.

If the content is the same, the user has their cache enabled. If it is different, they do not.

Give it a bash and see how you go. As I said - not guaranteed to work, but sounds logical enough ;o)

Hope this helps,
Dan
 
Incidentally, to make sure your pages don't get cached, put these 3 meta tags in your head section:

Code:
<meta http-equiv="expires" content="Mon, 5 Jan 2004 11:00:00 GMT" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="pragma" content="no-cache" />

Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top