Chr*_*ris 5 javascript jquery caching numbers include
在已使用jquery的load函数加载的页面上,所有包含的javascript文件均包含参数'_',其值等于当前的unix时间戳,并在加载时加上3个额外的数字。
例如,如果我包含“ file.js”,则包含的实际文件将是“ file.js?_ = 1378360893522”。
它阻止了javascript文件的缓存,是否有任何方法可以阻止这种行为?
编辑:根据要求,这里是相关代码:
index.html:
<html>
<head>
<script type="text/javascript" src="js/jquery.min.js"></script>
</head>
<body>
<div id='new-page'></div>
</body>
<script>
$(document).ready(function() {
$('#new-page').load("another-page.html");
});
</script>
</html>
Run Code Online (Sandbox Code Playgroud)
another-page.html:
<html>
<head>
<script type="text/javascript" src="js/another-js-file.js"></script>
</head>
<body>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
“ another-js-file.js”被加载为“ another-js-file.js?_ = 1378425747710”
第二编辑:已回答。对于那些阅读此书的人,我将其load调用更改为以下内容:
$.ajax({
url: "another-page.html",
cache: true,
dataType: "html",
success: function(data){
$("#new-page").html(data);
}
});
Run Code Online (Sandbox Code Playgroud)
有人说某些插件可能会通过ajaxSetup将缓存设置为false,因此可能有必要在要缓存的ajax调用之前使用它:
$.ajaxSetup({cache:true});
Run Code Online (Sandbox Code Playgroud)