gpt4 book ai didi

angularjs - 更新缓存的模板

转载 作者:行者123 更新时间:2023-12-02 23:04:50 25 4
gpt4 key购买 nike

我使用了templateUrl,效果非常好!

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

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

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

最佳答案

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

  1. 使用$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);
  2. 使用文件版本控制每次更改时重命名文件 - 即,如果文件的第一个版本是 template-1.0.1.html,当您进行一些代码更改时,将其重命名为 template-1.0.2.html 等等。这样,每次您进行一些更改时都会下载新文件。

关于angularjs - 更新缓存的模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26212821/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com