在使用 jquery 的 load 函数加载的页面上,包含的所有 javascript 文件都有一个参数“_”,其值等于当前 unix 时间戳加上加载时的 3 个额外数字。
例如,如果我包含“file.js”,则包含的实际文件将是“file.js?_=1378360893522”。
它阻止了 javascript 文件的缓存,有没有办法阻止这种行为?
编辑:这里要求的是相关代码:
索引.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>
另一个页面.html:
<html>
<head>
<script type="text/javascript" src="js/another-js-file.js"></script>
</head>
<body>
</body>
</html>
“another-js-file.js”加载为“another-js-file.js?_=1378425747710”
第二次编辑:已回答。对于那些阅读本文的人,我将负载调用更改为更像:
$.ajax({
url: "another-page.html",
cache: true,
dataType: "html",
success: function(data){
$("#new-page").html(data);
}
});
有人说某些插件可能会通过 ajaxSetup 将缓存设置为 false,因此可能需要在要缓存的 ajax 调用之前使用它:
$.ajaxSetup({cache:true});