HTML的缓存清除 [英] Cache-busting for html
问题描述
我已经了解了这种称为缓存清除的方法,该方法使我们可以向js和css文件中添加版本参数,以便客户端在每次更新时都不必清除缓存。但是,我没有阅读有关html的任何文章。
Ive read about this method called cache-busting that allows us to add version parameters to our js and css files so that clients wont have to clear cache every time we have an update. However, I didn`t read any about html.
有没有一种方法可以让我们加载最新的html文件更改而无需清除缓存?
Is there any method that allows us to load latest html file changes without clearing the cache?
P.S。我对其他人一无所知,但我发现缓存模板的是angularjs。我还是发布了自己的解决方案
P.S. I dont know about others but I just discovered that it is angularjs that is caching my templates. I posted my own solution anyway
推荐答案
解决了。
只需将一个参数字符串附加到引用您的html文件的路由中,就像我们在css和js的缓存清除操作中所做的一样。
Solved it. Just append a parameter string to your routes that are referencing your html files just like what we did on cache-busting for css and js.
.when('/login', {
templateUrl: "../views/login.html?v=" + versionNumber,
controller: "LoginController"
})
其中 versionNumber是全局变量。
Where 'versionNumber' is a global variable.
这篇关于HTML的缓存清除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!