加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 更新缓存的模板

发布时间:2020-12-17 06:58:11 所属栏目:安全 来源:网络整理
导读:我使用templateUrl,效果很好! app.directive('myDir',function() { return { templateUrl: 'partials/directives/template.html' };}; 但是……当我对这些模板进行更改时,它不会更新.在开发过程中,这不是一个大问题,因为我知道更新了什么,可以手动清除缓存.
我使用templateUrl,效果很好!

app.directive('myDir',function() {
    return {
        templateUrl: 'partials/directives/template.html'
    };
};

但是……当我对这些模板进行更改时,它不会更新.在开发过程中,这不是一个大问题,因为我知道更新了什么,可以手动清除缓存.

但我无法清除所有用户的缓存.有没有办法做到这一点?喜欢使用CACHE-CONTROL metatag或类似的东西?

解决方法

据我所知,你有两个选择 –

>使用$cacheFactory服务删除旧缓存
获取模板后,Angular会将其缓存在默认的$templateCache服务中

// Please note that $cacheFactory creates a default key '$http'

var cache = $cacheFactory.get('$http');

// The remove() function removes a key-value pair from the cache,// if it’s found. If it’s not found,then it just returns undefined.

cache.remove(your url);

>使用文件版本控制每次更改时重命名文件 – 即如果您的文件的第一个版本是template-1.0.1.html,则在进行一些代码更改时将其重命名为template-1.0.2.html,依此类推.这样,每次进行一些更改时都会下载新文件.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读