javascript 强制浏览器清除 Angular 环境中的缓存
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47816279/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Force browser to clear cache in Angular environment
提问by Phil
There is a popular question on how to force-clear the cache of the browser in a VanillaJS application, with the general consensus being, setting the name of the .js-script or the scripts arguments to a new value: Force browser to clear cache
有一个关于如何在 VanillaJS 应用程序中强制清除浏览器缓存的流行问题,普遍的共识是,将 .js-script 的名称或脚本参数设置为新值:强制浏览器清除缓存
How can I achieve this with Angular (currently 5.1 in AngularCLI/Webpack build), so every time I release the code in production (with AOT), a new version is built? I would use date-hashing instead of indexing, but the main question is: where can I set it (eg the script name/arguments)? In development, where the CLI takes care of rebuilding the app, this is not an issue, just in production!
我如何使用 Angular(AngularCLI/Webpack 构建中的当前 5.1)实现这一点,所以每次我在生产中发布代码(使用 AOT)时,都会构建一个新版本?我会使用日期散列而不是索引,但主要问题是:我可以在哪里设置它(例如脚本名称/参数)?在开发中,CLI 负责重建应用程序,这不是问题,只是在生产中!
回答by LLai
By setting your build command to target production ng build --target=production, the cli automatically hashes your js files. Here are the docsYou can also set the command manually if you wanted it on dev ng build --output-hashing=all
通过将您的构建命令设置为目标 production ng build --target=production,cli 会自动散列您的 js 文件。这里是文档如果你想在开发者上手动设置命令你也可以ng build --output-hashing=all

