Skip to content
Advertisement

How do I fingerprint images and other static assets in Ionic for cache busting?

I have extended default web pack config in Ionic v3 for forcing cache busting.

I am able to fingerprint generated JavaScript artifacts, but I am unable to fingerprint images and JSON files under the assets folder. I took Help from Bundled files and cache-busting.

An excerpt of webpack config.js

JavaScript

The above is the approach for fingerprinting JavaScript bundles, and it’s working fine. I want to add hashes/fingerprint images and JSON files inside the assets folder. I used the same approach for images also, but it did not work.

I have extended webpack config.js and added a new rule for images. By default webpack directly copies the images and assets to the output folder.

Copy Config.js

JavaScript

Here images and other assets are directly copied. I have added a new rule in extended webpack.config.js, but the build process is ignoring it. How do I fix this issue?

Excerpt of webpack config.js

JavaScript

entire Webpack.config.js

JavaScript

Advertisement

Answer

Eventually, I used gulp for fingerprinting static assets.

  1. Drop Angular Output hashing and build the application.ng build --prod --aot --output-hashing none .
  2. post-build execute a gulp script which would fingerprint all the assets and update the references.
JavaScript

gulpfile.js

JavaScript

Add a new script in package.json

"gulp-revision": "gulp revision"

Execute npm run gulp-revision Post-build.

Solving Browser Cache Hell With Gulp-Rev

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement