强制浏览器在Angular环境中清除缓存 [英] Force browser to clear cache in Angular environment

查看:710
本文介绍了强制浏览器在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

这篇关于强制浏览器在Angular环境中清除缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆