更新缓存的模板

Snæ*_*ørn 6 caching browser-cache angularjs angularjs-directive angular-template

我利用templateUrl它,效果很棒!

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

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

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

Rab*_*abi 2

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

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

    \n\n
    // Please note that $cacheFactory creates a default key '$http'\n\nvar cache = $cacheFactory.get('$http');\n\n// The remove() function removes a key-value pair from the cache, \n// if it\xe2\x80\x99s found. If it\xe2\x80\x99s not found, then it just returns undefined.\n\ncache.remove(your url);\n
    Run Code Online (Sandbox Code Playgroud)
  2. \n
  3. 使用文件版本控制\n每次更改时重命名文件 - 即,如果文件的第一个版本是 template-1.0.1.html,则当您进行某些代码更改时,将其重命名为 template-1.0.2.html 等。这样,每次您进行一些更改时都会下载新文件。

  4. \n
\n