9

Is there a jQuery approach to detect whether a page is loaded from the browser cache OR it has been received from the server by HTTP request?

Googlebot
  • 15,159
  • 44
  • 133
  • 229
  • Do you mean to check whether the current page was loaded from cache, or do you mean during an Ajax-request? – Christofer Eliasson Mar 26 '12 at 10:19
  • 1
    Read this [http://stackoverflow.com/questions/4433769/is-my-page-being-loaded-from-the-browser-cache][1] [1]: http://stackoverflow.com/questions/4433769/is-my-page-being-loaded-from-the-browser-cache – Duke Mar 26 '12 at 10:20
  • @ChristoferEliasson I want to know if visitor is visiting the updated page or old version cached on his browser. – Googlebot Mar 26 '12 at 10:25

3 Answers3

4

The following article should answer your question:

Detecting when a page is loaded from the browser cache.

The concept of the above article is that at every request you set the cookie from the server side and check the cookie using JavaScript (or jQuery). if the cookie matches that of the previously requested page, then it is a cached page. If it doesn't, it is a fresh page.

Hope that helps.

Tabrez Ahmed
  • 2,830
  • 6
  • 31
  • 48
3

You could also use Navigation Timing to measure the network latency in great detail.

Here is a good article: http://www.html5rocks.com/en/tutorials/webperformance/basics/

If the time difference between fetchStart and responseStart is very low, the page was loaded from cache, for example.

stewe
  • 41,820
  • 13
  • 79
  • 75
1

Serve the page server-written timestamp value var origin = <%=someTimeStamp %>;, read it and compare against a JavaScript generated value representing the current time.

Note: The client timestamp and the server timestamp would be different because there are chances the client system time is wrong and also the server and the client systems may not be from the same time zone. This has to be taken care.

Tabrez Ahmed
  • 2,830
  • 6
  • 31
  • 48
Alex K.
  • 171,639
  • 30
  • 264
  • 288