重新加载页面没有缓存重新验证

时间:2017-02-24 16:17:00

标签: javascript jquery html caching

我的服务器向客户端发送包含许多组件的页面。 我的所有图片,js和css都被缓存了。

在我的页面中,有一个像这样的JavaScript:

function refresh(){
    window.location.reload();
}
var timer = setInterval("refresh()", 60000);

事实上,我需要经常重新加载我的页面以验证我的服务器上是否有新的信息。

但问题是:当我重新加载页面时,我的所有组件(图片,css,js ......)都被重新验证。我想只检查我的信息,但不检查所有组件。

所以,我想知道是否可以重新验证我的网页的一部分,没有图片,js和css重新验证

由于

4 个答案:

答案 0 :(得分:0)

尝试使用ajax加载:仅从服务器加载新信息。 此外,自动重新加载页面对用户来说非常烦人。

答案 1 :(得分:0)

在js,css的网址末尾添加查询随机值,例如

<script src="a.js?timestamp=1234567">

并在每次加载页面时更改时间戳值。

答案 2 :(得分:0)

header("Expires: Tue, 01 Jan 2000 00:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

答案 3 :(得分:0)

You can use local storage to check the page first time or reload then avoid validate in document loading.

// Check browser support
if (typeof(Storage) !== "undefined") {
// Store
localStorage.setItem("storage", "reload");
// Retrieve
if(localStorage.getItem("reload") == "reload")
{
 var isReload = true;
 }
}
 if(!isReload)
 {
   //validation logic
 }

function refresh(){
window.location.reload();
}
var timer = setInterval("refresh()", 60000);


//you have to clear the storage once you are logging out or leaving 
function removeloacalstorage(name)
{
  //here name is "storage"
   localStorage.removeItem(name);
 }
相关问题