3 ms·
If you’re using Webpack you can emit chunks by their content hash, which means the file names don’t change even when your commit changes. This way, a new deplo
by supriyo-biswas 3y ago
If you’re using Webpack you can emit chunks by their content hash, which means the file names don’t change even when your commit changes.
This way, a new deployment of your application doesn’t cause new assets to be served to users, and maintains the speed of your website.
- JimDabell 3y ago> If you’re using Webpack you can emit chunks by their content hash You’re talking about this in terms of chunks of JavaScript, but static asset caching is something you should be doing for all static assets, not just JavaScript. Whenever I’ve seen somebody use Webpack content hashing for this, they’ve done it for JavaScript and CSS and forgot about basically every other type of file. And also, now you are tied to only referencing those assets via JavaScript because you have to get the URLs from Webpack, whereas with a URL prefix you can just use relative URLs which work in other contexts as well.
- supriyo-biswas 3y agoYeah, for this I like to append the deployment time to the asset paths from within my application; however in the case of static websites it can be a problem.
- jdsleppy 3y agoYou aren't tied to only referencing things from JS: you can have Webpack emit a manifest file with a JSON object mapping from the original filename to the hashed one. Then oldschool web app code can reference these fingerprinted files using the manifest. To fingerprint files you normally wouldn't import in JS, you can 1) import them in JS anyway just for the bundling side effect or 2) use a Webpack copy plugin to copy all font files, for example, to the build directory and fingerprint them.