Skip to content
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

Merged

Conversation

pistachiology
Copy link
Contributor

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

JSON.stringify({
assetsByChunkName: assets,
}),
JSON.stringify(stats.toJson()),
Copy link

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 })),
Copy link
Contributor Author

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 ?

Copy link

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.

@KyleAMathews
Copy link
Contributor

This is looking great! Could you an a little example site to demo how this works?

@pistachiology pistachiology changed the title [WIP][v2] Build-html static file using the webpack magic comment to provide the link rel. [v2] Build-html static file using the webpack magic comment to provide the link rel. Jun 16, 2018
@pistachiology
Copy link
Contributor Author

@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)}`
Copy link
Contributor

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 👍)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@KyleAMathews KyleAMathews merged commit d30f1c2 into gatsbyjs:v2 Jun 16, 2018
@KyleAMathews
Copy link
Contributor

Thanks!

@jlengstorf
Copy link
Contributor

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:

  1. We’d like to send you some Gatsby swag. As a token of our appreciation, you can go to the Gatsby Swag Store and log in with your GitHub account to get a coupon code good for one free piece of swag. (We’ve got t-shirts and hats, plus some socks that are really razzing our berries right now.)
  2. If you’re not already part of it, we just invited you to join the Gatsby organization on GitHub. This will add you to our team of maintainers. You’ll receive an email shortly asking you to confirm. By joining the team, you’ll be able to label issues, review pull requests, and merge approved pull requests.

If you have questions, please don’t hesitate to reach out to us: tweet at @gatsbyjs and we’ll come a-runnin’.

Thanks again! 💪💜

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants