【发布时间】:2016-09-22 17:48:26
【问题描述】:
我喜欢包含带有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
【问题讨论】:
-
您可以使用浏览器网络捕获来检查它。对于第一个请求,状态必须为 200,如果第二个请求的状态为 304,或者我们没有第二个请求。我们可以确定模板被缓存了
-
我相信
$templateCache服务做到了docs.angularjs.org/api/ng/service/$templateCache -
html 被缓存,不会创建额外的请求。我来到这里实际上是想找到如何克服缓存..
标签: javascript angularjs