javascript AngularJS ng-include 缓存

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21935446/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 22:02:14  来源:igfitidea点击:

AngularJS ng-include caching

javascriptangularjs

提问by MR.ABC

i like to include templates with the ng-includeattribute. I like to know if the templates getting cached while using the the same url multiple times.

我喜欢包含具有ng-include属性的模板。我想知道在多次使用相同的 url 时模板是否被缓存。

<div ng-include src="'./Views/temp.html'"></div> //get request temp.html
<div ng-include src="'./Views/temp.html'"></div> //load from cache

回答by drew_w

Caching istypically used - but its not on the part of angular but instead on the part of the browser. You can see this by running Fiddler and seeing what happens when your page loads. If you get a 304 result code back from the server it means that the page hasn't changed - so it will be pulled from cache.

缓存通常用于-但它不是对角的一部分,而是在浏览器上的一部分。您可以通过运行 Fiddler 并查看页面加载时发生的情况来查看这一点。如果您从服务器返回 304 结果代码,则意味着该页面没有更改 - 因此它将从缓存中拉出。

Force Reload

强制重装

The only good way to consistently force a reload is to add query string as follows (you can replace "i" with any variable you would like and the numbers just need to be random - not previously used numbers):

持续强制重新加载的唯一好方法是按如下方式添加查询字符串(您可以将“i”替换为您想要的任何变量,并且数字只需要是随机的 - 而不是以前使用的数字):

<div ng-include src="'./Views/temp.html?i=1000'"></div> // get request temp.html
<div ng-include src="'./Views/temp.html?i=1001'"></div> // force the page to load!

Hope that helps!

希望有帮助!

回答by Kapil Lohakare

In my case, I opened the "Incognito Window" still it was showing me the cached version. I inspected the same and found the .html pages were having 200 status.

就我而言,我打开了“隐身窗口”,它仍然向我显示缓存版本。我检查了同样的内容,发现 .html 页面有 200 个状态。

One easy way to overcome this problem is to use "Clear Browser cache" in the "Network" tab. enter image description here

解决此问题的一种简单方法是使用“网络”选项卡中的“清除浏览器缓存”。 在此处输入图片说明

Hope this helps!

希望这可以帮助!