Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 805
Phil Avatar asked Dec 14 '17 14:12

Phil


People also ask

How do I force browser to clear cache?

But you can bypass the cache and force a complete refresh by using some simple hotkeys: Windows and Linux browsers: CTRL + F5. Apple Safari: SHIFT + Reload toolbar button. Chrome and Firefox for Mac: CMD + SHIFT + R.

Can I delete angular cache?

Angular cacheThere is no command to clear the cache, just run rm -rf . angular/cache .

What is cache busting angular?

To prevent visitors from being served with an older, cached version of the file, which might lack some translation, you can employ a cache-busting functionality. This entails attaching a unique version identifier to the file, which ensures that a fresh version is fetched, instead of a stale, cached version.

Can you clear cache for a specific website edge?

Delete cookies from a specific siteUnder Cookies and data stored, select Manage and delete cookies and site data > See all cookies and site data and search for the site whose cookies you want to delete. Select the down arrow to the right of the site whose cookies you want to delete and select Delete .


1 Answers

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

like image 142
LLai Avatar answered Oct 05 '22 06:10

LLai