Cache-busting for html

时光毁灭记忆、已成空白 提交于 2019-12-23 04:31:40

问题


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.

Is there any method that allows us to load latest html file changes without clearing the cache?

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


回答1:


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"
    })

Where 'versionNumber' is a global variable.




回答2:


EDIT

The link in the original answer is broken.

Aside from the accepted answer, the answers on this question offer interesting alternatives depending upon your build process.

ORIGINAL

You should be able to force reload the browser via js, while applying a hash to the url, via page-specific javascript that exists only on an updated version of the html file.

This would allow you to know when you are receiving the latest version of the file.

https://developer.zendesk.com/blog/static-file-cache-busting



来源:https://stackoverflow.com/questions/42849876/cache-busting-for-html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!