[英]Force browser to clear cache in Angular environment
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?我如何使用 Angular(AngularCLI/Webpack 构建中的当前 5.1)实现这一点,所以每次我在生产中发布代码(使用 AOT)时,都会构建一个新版本? 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!在开发中,CLI 负责重建应用程序,这不是问题,只是在生产中!
By setting your build command to target production ng build --target=production
, the cli automatically hashes your js files.通过将您的构建命令设置为目标生产ng build --target=production
,cli 会自动散列您的 js 文件。 Here are the docs You can also set the command manually if you wanted it on dev ng build --output-hashing=all
这里是文档如果你想在 dev ng build --output-hashing=all
上手动设置命令,你也可以手动设置
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.