question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add filename pattern option to allow using contenthash in filenames

See original GitHub issue

Since 5.0.0 it’s possible to add [contenthash] etc. to the publicPath. This allows creation of urls like this:

myweb.tld/assets/[contenthash]/manifest.json`

But this also means that regardless of which file generated by this plugin changed, the hash always changes for all files. Meaning even unchanged files have to be refetched to be cached.

Webpack itself provides filename patterns to allow for file-specific cache busting. E.g:

output: {
  filename: '[name].[contenthash].bundle.js',
  ...
}

It would be great if this could be somehow archived with this plugin as well.

e.g add options for file name generation:

new MiniCssExtractPlugin({
  filenamePattern: '[name].[contenthash].[ext]'
})

this would cover all generated filetypes (manifest, images, …) with a single option.

Related issues: #240

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
leevigrahamcommented, May 20, 2021

You can do this with prefix: ‘assets/[contenthash]/’

This results in the same issue as @jthomaschewski mentioned:

But this also means that regardless of which file generated by this plugin changed, the hash always changes for all files. Meaning even unchanged files have to be refetched to be cached.

I believe what @jthomaschewski wanted was to have the files written using a file pattern:

assets/[name].[contenthash].[ext]

2reactions
PeterKottascommented, May 31, 2021

I think this should be reopened or am I missing something?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Adding Hashes to Filenames - SurviveJS
According to Steve Souders, attaching the hash to the filename is the most performant option. Setting up hashing#. The build needs tweaking to...
Read more >
[Feature] Toggle contenthash for all output filenames #518
When disabled, filenames are untouched. When enabled, the content hash is calculated and injected into all file names ( bundle.js -> bundle.[ ...
Read more >
webpack: use hash file name in html template - Stack Overflow
The html-webpack-plugin already handles putting in script tags for you using the correct naming pattern. So you can just omit the script tag...
Read more >
Adding Hashes to Filenames | webpack surviveJS
According to Steve Souders , attaching the hash to the filename is the most performant option. # Setting Up Hashing. The build needs...
Read more >
Caching - webpack
We can use the output.filename substitutions setting to define the names of our ... The [contenthash] substitution will add a unique hash based...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found