-
Notifications
You must be signed in to change notification settings - Fork 243
Move webpack manifest out from index chunk(Improve long term caching of index chunk) #472
base: master
Are you sure you want to change the base?
Conversation
@ctrlplusb any thoughts on this? I ran into the issue while using react-universally in production for an application. |
I would strongly recommend this approach is taken. This is a huge issue if you have a CDN in front of your files and it can be very tricky to debug. Users in one part of the world can get a cached manifest pointing to files that no longer exist (completely breaking the site), while other users in a different region will get the new manifest and everything will work. I believe the issue is with the md5 hasher: The solution is either dhruvparmar372's which I think is ideal because it increases the likelihood of serving a cached index or removing webpack-md5-hash like this (not making a PR because in the end I think we should break out the manifest):
|
const headerElements = removeNil([ | ||
...ifElse(helmet)(() => helmet.title.toComponent(), []), | ||
...ifElse(helmet)(() => helmet.base.toComponent(), []), | ||
...ifElse(helmet)(() => helmet.meta.toComponent(), []), | ||
...ifElse(helmet)(() => helmet.link.toComponent(), []), | ||
ifElse(clientEntryAssets && clientEntryAssets.css)(() => stylesheetTag(clientEntryAssets.css)), | ||
...ifElse(helmet)(() => helmet.style.toComponent(), []), | ||
ifElse(process.env.BUILD_FLAG_IS_DEV === 'false')(() => inlineScript(webpackManifestScript)), | ||
]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, I believe this should be in the bodyElements array
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey, could you give a reasoning for the same? i don't see much difference as long as the manifest is loaded before webpack entry files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, there is actually no difference, but I just thought to keep it consistent since other inlineScript is used inside the bodyElements.
I actually tried out this resolution by @dhruvparmar372 , however it will fail for service worker offline, as I get MIME Type error for application/javascript for the manifest.json. |
@dhruvparmar372 @sinwailam193 @slipo what solution did you folks end up with here? |
Enables index chunk hash to become independent of children chunk hashes. The manifest is inlined with every server rendered route in production mode.
@oyeanuj i feel this approach should be taken due to the issues pointed above. |
Issue
index
chunk hash does not change if any of the children chunks content changes.Steps to reproduce
yarn run build
on master branch.build/client/index-{}.js
file for later referenceshared/components/DemoApp/AsyncCounterRoute/CounterRoute.js
yarn run build
.build/client/index-{}.js
file.Both versions of
index-{}.js
file have same file names but different hash name for"counter"
chunk inside them.This is currently an issue with webpack webpack/webpack#1856
A possible fix for same is to use https://github.com/roscoe054/webpack-hashed-module-id-plugin
but it tends to generate new chunk names on every build even for unchanged chunks. This hampers long term caching of those chunks
Another side effect of the issue is that since webpack manifest is currently part of the
index
chunk on every change to any child chunk theindex
chunk's hash will change.Fix
The manifest is inlined with every server rendered route in production mode. This PR enables the same in production mode