【问题标题】:Handle version of files in AngularJS在 AngularJS 中处理文件的版本
【发布时间】:2018-09-24 19:39:10
【问题描述】:

我想知道是否存在任何添加后缀的方法

'app/account/script.js?v=1.0',
'app/account/style.css?v=1.0',

对 AngularJS 中的所有请求,包括对 css 和 js 文件的请求。

使用拦截器我们可以做这样的事情 Angular template versioning

但不幸的是,这不是我的解决方案。

谢谢

【问题讨论】:

  • @davidkonrad 我想使浏览器缓存无效。
  • 没错,我想使用 AngularJS 使浏览器缓存失效
  • 谢谢,我去看看!!!

标签: angularjs version assets browser-cache


【解决方案1】:

我解决了这个

首先在您的 app.js 中

app.value('version', '1.0.0');

然后我们添加一个新指令

app.directive('disableCache', function(version) {
    return {
        restrict: 'A',
        replace: false,
        link: function(scope, elem, attr) {
            attr.$set("src", attr.src +  "#v=" + version);
        }
    };
});

我们更新我们的 html

<script src="scripts/js/filters.js" disable-cache></script>

将是

<script src="scripts/js/filters.js#v=1.0.0" disable-cache=""></script>

【讨论】:

    猜你喜欢
    • 2012-10-24
    • 1970-01-01
    • 2016-06-07
    • 2015-08-29
    • 2013-07-16
    • 2014-12-18
    • 2015-12-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多