通过jQuery检测浏览器缓存

通过jQuery检测浏览器缓存

问题描述:

是否有 jQuery 方法来检测页面是从浏览器缓存加载还是通过HTTP请求从服务器收到?

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?

以下文章应该回答你的问题:

The following article should answer your question:

检测从浏览器加载页面的时间缓存。

上述文章的概念是,每次请求都要从服务器端设置cookie并使用JavaScript检查cookie (或jQuery)。如果cookie与先前请求的页面的cookie匹配,那么它是一个缓存页面。如果没有,那就是一个新的页面。

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.

希望有所帮助。