强制浏览器在Angular环境中清除缓存
关于如何在VanillaJS应用程序中强制清除浏览器的缓存有一个流行的问题,一般的共识是,将.js脚本的名称或脚本参数设置为新值:强制浏览器清除缓存
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
我如何使用Angular实现这一点(目前在AngularCLI / Webpack构建中为5.1),因此每次我在生产中发布代码(使用AOT)时,都会构建一个新版本?我会使用日期散列而不是索引,但主要问题是:我在哪里可以设置它(例如脚本名称/参数)?在开发中,CLI负责重建应用程序,这不是问题,只是在生产中!
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!
通过设置你的构建命令目标生产 ng build --target = production
,cli会自动哈希你的js文件。以下是 docs 也可以手动设置命令,如果你想在dev ng build --output-hashing = all
By setting your build command to target production ng build --target=production
, the cli automatically hashes your js files. Here are the docs You can also set the command manually if you wanted it on dev ng build --output-hashing=all