-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[v2] Build-html static file using the webpack magic comment to provide the link rel. #5901
[v2] Build-html static file using the webpack magic comment to provide the link rel. #5901
Conversation
JSON.stringify({ | ||
assetsByChunkName: assets, | ||
}), | ||
JSON.stringify(stats.toJson()), |
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.
Since the webpack stats can be very big (megabytes), I don’t recommend writing the whole stats to the file. You can use stats.toJson()
so that the childAssets
are calculated and available, but we should make the stats file as small as possible.
What I recommend is this: Bring back the assetsByChunkName
but instead of being an array of string (e.g. { app: ['app-hash.js'] }
, make it an array of link entries, e.g. { app: { assets: ['app-hash.js'], childAssets: ... } }
).
JSON.stringify({ | ||
assetsByChunkName: assets, | ||
}), | ||
JSON.stringify(stats.toJson({ all: false, assets: true, chunkGroups: true })), |
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.
@dtinth I just check webpack/stats.js and there's an option all
so I could reduce webpack.stats.json size without need to use custom code. maybe can I do this instead ? or It's still better to have smaller file sizes ?
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.
Hmm… This could work as well.
This is looking great! Could you an a little example site to demo how this works? |
@KyleAMathews I provide demo in examples/using-prefetching-preloading-modules. Could you please review the code ? Thanks! |
@@ -253,7 +276,7 @@ export default (pagePath, callback) => { | |||
) | |||
|
|||
const bodyScripts = scripts.map(s => { | |||
const scriptPath = `${pathPrefix}${JSON.stringify(s).slice(1, -1)}` | |||
const scriptPath = `${pathPrefix}${JSON.stringify(s.name).slice(1, -1)}` |
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.
We should add bundles that are marked to be prefetched here as that defeats the point of prefetching. Prefetching is lower priority in the background. If you add it as a script tag as well, it'll be loaded at high priority.
I'm making another small fix in the codebase near your changes so will fix this too 👍)
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.
Thanks!
Thanks! |
Hiya @pistachiology! 👋 This is definitely late, but on behalf of the entire Gatsby community, I wanted to say thank you for being here. Gatsby is built by awesome people like you. Let us say “thanks” in two ways:
If you have questions, please don’t hesitate to reach out to us: tweet at @gatsbyjs and we’ll come a-runnin’. Thanks again! 💪💜 |
According to #5748.
We need to merge into branch v2 and upgrade webpack version to >4.6.0 for webpackPrefetch feature instead.
This PR solves this issue: #5683