AngularJS NG-包括缓存 [英] AngularJS ng-include caching

查看:325
本文介绍了AngularJS NG-包括缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想包括与 NG-包括属性模板。我想知道在使用相同的URL多​​次如果获取缓存中的模板。

 < D​​IV NG-包括SRC =./查看/ temp.html'>< / DIV> // get请求temp.html
< D​​IV NG-包括SRC =./查看/ temp.html'>< / DIV> //从缓存加载


解决方案

缓存的的通常使用 - 但它不是对部分棱角分明,而是在浏览器的一部分。您可以通过运行小提琴手,看到当你的页面加载时会发生什么看到这一点。如果你得到一个304的结果code从服务器返回这意味着该页面没有改变 - 所以它会从缓存中取出

强制刷新

唯一的好办法始终强制重新加载是添加查询字符串如下(可以代替我与任何变量,你想和这些数字只是需要是随机的 - 而不是previously使用的号码):

 < D​​IV NG-包括SRC =./查看/ temp.html I = 1000?'>< / DIV> // get请求temp.html
< D​​IV NG-包括SRC =./查看/ temp.html I = 1001'>< / DIV> //强制页面加载!

希望帮助!

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

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

解决方案

Caching is typically 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.

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):

<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!

这篇关于AngularJS NG-包括缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆