【发布时间】:2014-05-01 14:24:03
【问题描述】:
我正在尝试使用 ajax 的缓存功能。但它不适用于我的要求。我想缓存我的所有请求。这是我的代码
<script type='text/javascript' src='//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js'></script>
<script type='text/javascript'>
jQuery(document).ready(function (jQuery) {
call_ajax();
});
jQuery(window).scroll(function(){
call_ajax();
});
function call_ajax(){
jQuery.ajax({
type: "get",
cache : true,
data: {offset : 3},
dataType : "html",
url: 'http://localhost/contents.php',
success: function(returnData){
jQuery('.ajaxcontents').append(returnData);
},
});
}
</script>
<div id="ajaxcontents"></div>
在文件 contents.php 中,我将标题设置如下。
header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', strtotime("+5 days")), true);
header("Pragma: public");
header("Cache-Control: public");
当我在 google 检查工具(在网络选项卡下)检查请求详细信息时,它总是第一次显示 200,之后,当我滚动它时,它显示 200(来自缓存)。为什么即使在我重新加载同一页面后,它也没有第一次显示 200(来自缓存)?
【问题讨论】:
-
@HeroFTime :它不相似。因为我的过期标头总是在未来。
-
当您重新加载页面时,您确定您没有同时进行缓存重新加载吗?您的任何资产是否从缓存中返回?