在angularjs中预取模板有什么好处吗? [英] Are there any benefits of pre-fetching templates in angularjs?
问题描述
我有关于优化应用程序的问题。我有多个指令的应用程序,所以我决定建立单分钟。为他们所有的CSS和JS文件。但与此同时,我正在考虑另一种方式。
如果我还要构建一个大而简化的HTML文件,该怎么办? Angular允许包含来自脚本
标记的模板:
< script type =text / ng-templateid =tempName>
模板内容
< / script>
如果是这样,将每个指令的HTML注入一个大文件?在需要时它会比多个小文件和触发请求更好吗?
我知道,如果我们有多个视图的大应用程序,但用户只停留在其中的少数应用程序,它不会那么好。我的想法是为更小的指令构建这个文件,这不会导致任何问题,对吗?
您怎么看待这个?
像这样的缓存模板的优点和缺点。优点: 缺点: 如果专业人士超过您的应用程序,您可能需要使用一些构建工具,如 I have question concerning optimising application. I have application with multiple directives, so I decided to build single min. css and js file for them all. But at the same time, I was thinking of another way. What if I would also build one big, minimalised HTML file? Angular allows including templates from If so, what would be downsides of injecting every directive's HTML in one big file? Would it be any better than multiple small files and firing request when they are needed?
I know, that it wouldn't be so good if we have big application with multiple views, but user only stays at few of them. My idea is to build this file for smaller directives, that shoulnd't cause any problems, right? What do you think of this? Like anything there are pros and cons to this approach of caching templates. Pros: Cons: If the pros exceed in your application you may want to use some build tool such
as: 这篇关于在angularjs中预取模板有什么好处吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
$ b $预取也预先编译准备使用的模板,因为它放入templateCache中。 b
:
script
tag:<script type="text/ng-template" id="tempName">
Template content
</script>