Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Option to write "First Load Size" data to file #10383

Closed
merrywhether opened this issue Feb 2, 2020 · 8 comments
Closed

Option to write "First Load Size" data to file #10383

merrywhether opened this issue Feb 2, 2020 · 8 comments

Comments

@merrywhether
Copy link

Feature request

Is your feature request related to a problem? Please describe.

We'd previously used the bundlesize package in CI in order to monitor the growth of our application and prevent accidental imports of test libs, etc. With the switch to the new chunking strategy, the hash-based names of the new chunks breaks this approach (we previously just watched chunks/commons.*.js). But the new "First Load Size" data could easily replace this functionality, if it were easily accessible (I'm not super keen on redirecting and parsing stdout).

Describe the solution you'd like

Would it be possible to add a configuration option to next.config that enabled also writing the size data to a json file such that it could be then analyzed by other tools?

Describe alternatives you've considered

Capturing and parsing the stdout of a yarn build command.

@Timer
Copy link
Member

Timer commented Feb 3, 2020

Hey! We probably won't a file dedicated to file sizes as it's too specialized.

You can self-compute this using .next/build-manifest.json, though!

@Timer Timer closed this as completed Feb 3, 2020
@timneutkens
Copy link
Member

I'd like to keep this open, it's an interesting idea.

@timneutkens timneutkens reopened this Feb 3, 2020
@merrywhether
Copy link
Author

merrywhether commented Feb 8, 2020

Is this something you'd take a PR for, if I was able to get approval from my company? The addition actually looks pretty straightforward in next/build/index, since the data is all there in the pageInfos structure.

Thinking about it more, seems like the best approach could actually be writing out that entire data structure such that people can programmatically interact with the data in it, since people might want to assert static renderability or other things as well. persistPageStatsToFile or something could just add pageStats.json to .next/?

@timneutkens
Copy link
Member

We’d have to figure out the exact semantics, we’re currently focusing on other things (SSG, rewrites/redirects) but eventually we’ll add this when we know the right semantics needed to build these kind of tools.

@jtthackery
Copy link

jtthackery commented Mar 14, 2020

I was just looking at the @next/bundle-analyzer package to do something like this, would it be possible for that to take in some optional config for output location and type (i.e. json or text instead of html)? It seems like the underlying webpack-bundle-analyzer package can take those options.

Heh, just saw #11066 and the comment there, nevermind then!

@bobaaaaa
Copy link
Contributor

This should be now possible with nextjs 9.5. See: https://nextjs.org/blog/next-9-5#persistent-caching-for-page-bundles

Fixed by #13937

@merrywhether
Copy link
Author

merrywhether commented Jul 31, 2020

Stable hashes doesn't address the issue of trying to reason about the size of a page, since we'd still have to add up the bundle parts included in each page. Something like bundlesize could already work with the regex-addressable page files; the problem is that each page needs an "arbitrary" collection of intermediate JS files. That data is perfectly contained in the pageInfos data structure but not exposed post build so it can't be used for monitoring.

I know bundle size isn't everything when it comes to speed of delivery, but it's a pretty useful first line of defense against someone accidentally including something like faker outside of test files, for instance.

@izi-p
Copy link

izi-p commented Jan 21, 2021

Hey all,

I wrote a tiny script that computes "first load sizes" of your next.js pages, and store them in a json file.

https://github.com/izi-p/next-compute-first-load

Feel free to use it 🥰

Thank you

@vercel vercel locked and limited conversation to collaborators Apr 12, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants