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

Recipe for analyzing bundle size #9164

Closed
Lehoczky opened this issue Aug 22, 2024 · 9 comments · Fixed by #9974
Closed

Recipe for analyzing bundle size #9164

Lehoczky opened this issue Aug 22, 2024 · 9 comments · Fixed by #9974
Labels
add new content Document something that is not in docs. May require testing, confirmation, or affect other pages. help wanted Issues looking for someone to run with them!

Comments

@Lehoczky
Copy link

Lehoczky commented Aug 22, 2024

📚 Subject area/topic

Recipes and Guides

📋 Suggested page

https://docs.astro.build/en/recipes/analyze-bundle-size/

📋 General description or bullet points (if proposing new content)

When using client-side JavaScript libraries, it is important to keep track of how much they will increase the final js bundle size. Knowing this, we can optimize our page performance by potentially removing, or lazy-loading our client-side code. An official guide on how to analyze/visualize our page's js budle would be super helpful to do this.

For reference, some other frameworks have guides on how to do this:

🖥️ Reproduction of code samples in StackBlitz

No response

@Lehoczky Lehoczky added the add new content Document something that is not in docs. May require testing, confirmation, or affect other pages. label Aug 22, 2024
@sarah11918
Copy link
Member

Hey @Lehoczky this is a super cool idea!

We are a little stretched for writing resources at the moment (and have been for a while!) as we're writing a ton of new docs for our 5.0 beta release and all the changes/new features. But, I think this could be an interesting guide and would welcome anyone who wants to attempt writing one!

Putting a "help wanted" label on this one! Who's interested?

@sarah11918 sarah11918 added the help wanted Issues looking for someone to run with them! label Sep 9, 2024
@sarah11918
Copy link
Member

Just bumping this one for freshness and saying that I think the idea sounds cool if anyone wants to write something!

Will also note that things that aren't "issues" with docs will eventually be closed, since it's not something to "fix", but we do keep track of recipe ideas in this GitHub discussion for recipe ideas, to provide one place for people to look for inspiration about what to write, or to respond to let us know what would be popular! I'll link this idea there, too!

@branberry
Copy link
Contributor

Hey Sarah! I'd be interested in contributing/helping out with this. I'm not 100% familiar with the topic, and I'd need to do some research, but I'd be happy to take a try at it!

@sarah11918
Copy link
Member

Hi @branberry , thank you! Perhaps the easiest thing to do is post your thoughts/ideas here as you have them, then others can help with the collective knowledge! You could start by posting an outline of what should be included, and often others will participate and add ideas too. Feel free to use this space as a living conversation/draft! 💜

@branberry
Copy link
Contributor

Sounds great! I'll be heading to Japan for the next two weeks, so I'll be stepping away for a bit. When I come back, I'll work on posting an outline and share as soon as I can! Thank you for the input, really excited!

@sarah11918
Copy link
Member

Have a wonderful trip! Looking forward to seeing what you get up with here when you're back!

@branberry
Copy link
Contributor

I'm back!

For an initial iteration, I was looking at using the Rollup visualizer plugin which is commonly used as a plugin for Vite to visualize bundle sizes. This works, but the main drawback with this is that Astro, from what I understand, is a MPA as opposed to a SPA. This means that the bundle generated here doesn't necessarily reflect the bundle for all pages.

I did a little bit of searching, but I couldn't find anything specific to Astro for checking bundle sizes. I'll continue to dig around a bit, but I thought I would share the Rollup visualizer at least. Any thoughts on how I could tailor this to be Astro specific?

@sarah11918
Copy link
Member

Welcome back! Hope you had a wonderful trip. Maybe @bluwy has an idea of where to point you here?

@bluwy
Copy link
Member

bluwy commented Nov 6, 2024

Yeah rollup-plugin-visualizer is decent here and is usually what I recommend to use. You can put it in vite.plugins in the astro config and it should just work.

The tricky thing perhaps is that Astro does two Vite builds, the server and the client build, so there would be two visualizer outputs. Its readme shows an example of SvelteKit that also has multiple builds itself, so maybe it also works well for Astro.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
add new content Document something that is not in docs. May require testing, confirmation, or affect other pages. help wanted Issues looking for someone to run with them!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants