【问题标题】:Angular: Should static content be cached?Angular:应该缓存静态内容吗?
【发布时间】:2016-04-29 22:20:10
【问题描述】:

应该为 angularjs 应用程序缓存静态内容吗? 每次调用动态 html 模板都会使应用程序在等待动态 html 模板文件时变慢。

具体来说,我应该将以下内容添加到我的 WebConfig 设置中吗?

<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="60.00:00:00" />      <!--Cache Static content for 60 days--> 

【问题讨论】:

    标签: html asp.net angularjs asp.net-mvc caching


    【解决方案1】:

    您可以使用 $templateCache 来存储您的模板/视图。它们将成为您的 js 代码的一部分。

    如果您使用 gulp 或 grunt 来构建您的 javascript 代码,那么您可以设置任务,该任务将获取您的所有 html 文件并创建 js 文件(在其中您将所有视图添加到 $templateCache),您可以参考你的 index.html

    https://thinkster.io/templatecache-tutorial

    $templateCache 的 Gulp 插件

    https://www.npmjs.com/package/gulp-angular-templatecache

    【讨论】:

    • 谢谢。但是,我的问题中提到的静态内容缓存会达到相同的结果吗?
    猜你喜欢
    • 2011-08-19
    • 1970-01-01
    • 2015-08-07
    • 2015-10-04
    • 1970-01-01
    • 2011-04-26
    • 2016-08-13
    • 2020-09-17
    • 1970-01-01
    相关资源
    最近更新 更多