Chrome 缓存很多,但您可以强制它从服务器加载资源,而不是使用缓存清除将它们从缓存中取出:
加载模板:
var timestamp = (new Date()).getTime();
$ionicPopup.show({
scope: $scope,
title: 'Work!',
templateUrl: '/templates/roll-timer-popup.html?update='+timestamp
});
加载脚本/样式表:
<script src="myscripts.js?update=123..."></script>
<link rel="stylesheet" type="text/css" href="theme.css?update=123...">
对于脚本/样式表,您可以动态创建它们以及时间戳并在之后插入它们。
或者当您的脚本文件捆绑在一起时,您可以使用脚本将时间戳写入您的最终 index.html 文件以通过使用 nodejs 脚本进行部署,因为我为我的一个项目制作了这个脚本:
const fs = require('fs');
var filename = process.argv[2];
var regExp = /[.|\w]+[.]js/;
var contentToAttach = ['<!-- CONTENT ATTACHED BY '+process.argv[1]+' -->','you can put other content in here that is put into at the end of your file'];
fs.readFile(filename, {
flag : 'r',
encoding: 'utf-8'
},(err, oldFileContent) => {
if (err) throw err;
var fileContent = oldFileContent;
var oldScriptName;
var now = (new Date()).getTime();
var lastIndexPos = 0;
while (oldScriptName = oldFileContent.match(regExp)) {
var newScriptName = oldScriptName + '?update=' + now;
var newIndexPos = fileContent.indexOf(oldScriptName);
if (newIndexPos !== lastIndexPos) {
fileContent = fileContent.replace(oldScriptName, newScriptName);
lastIndexPos = newIndexPos;
}
else {
// same filename found
var fildContentSlice = fileContent.slice(newIndexPos+oldScriptName.length);
fildContentSlice = fildContentSlice.replace(oldScriptName, newScriptName);
fileContent = fileContent.slice(0,newIndexPos+oldScriptName.length)+fildContentSlice;
}
oldFileContent = oldFileContent.replace(oldScriptName, '');
}
var wholeContent = fileContent+'\n\r'+contentToAttach.join('\n\r');
fs.writeFile(filename,wholeContent, (err) => {
if (err) throw err;
console.log('File: '+filename+' is updated!');
});
});
它将 ?update=123... 插入到它可以在文件中找到的每个脚本标记中。
要在 shell 中执行此脚本,请编写:
node updateScript.js path_to_your_html_file
希望对你有帮助。