【发布时间】:2018-05-15 20:37:16
【问题描述】:
我正在尝试缓存我的 angularjs 应用程序的 html 文件,遵循以下建议:https://gist.github.com/ProLoser/6181026。
我正在向所有 html 文件(Angular ui bootstrap 使用的模板目录中的文件除外)附加一个动态缓存键,如 ?v=123456790。
对于他们自己文件中的部分,即app/views/customer/customer-history.html,这非常有效。但是,对于脚本形式的部分,例如<script type='text/ng-template' id='customer-history'> 找不到模板,请求服务器,导致404。
例如localhost:8080/customer-history/?v=1234567890
我可以看到有问题的模板在 $templateCache 中。使用 ng-template 的只是名称,即 customer-history,而单独的文件是路径 app/views/customer/customer-history.html,如您所料。
这是一个大型应用程序,因此将它们全部移动到自己的文件等中并非易事。我到处搜索,但我没有打开任何东西,所以我猜这是 templateCache 实现方式的基本内容。
我在构建过程中使用 gulp-templatecache 插件,但文档非常有限,我认为问题不存在。
我目前的解决方案是通过将inCache 函数装饰到$templateCache 工厂并在检查期间使用它来附加cacheKey,从而在附加版本号的函数中暂时跳过有问题的模板。但我觉得这有点忽略了重点。
【问题讨论】:
标签: angularjs angular-templatecache