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

Cleanup sprites (removing unused assets from bundle) #2446

Merged
merged 6 commits into from
Oct 3, 2024

Conversation

jake-low
Copy link
Contributor

This reduces the bundle size by about 400KB.

I moved several large SVG illustrations out of Sprites.js and into separate SVG files. These illustrations are mostly used in a single place (or not at all). By extracting them from Sprites.js and putting them in their own files, I was able to load them on demand (as <img src={...}> elements) rather than inlining them in the main JS bundle.

I also changed a couple of places where existing illustrations were being imported as import { ReactComponent as MyImage } from "./path/to/myimage.svg", preferring to instead do import myImage from "./path/to/myimage.svg". The difference between these is that the former causes Webpack to generate a React component for the SVG and include it in the bundle, whereas the latter just makes a hyperlink to the SVG. The former should mostly be avoided, especially for illustrations that are used on a single page or in a single modal, and can be loaded on demand when they're displayed rather than delaying the download of the initial bundle.

@jake-low jake-low force-pushed the jlow/cleanup-sprites branch from fa9b9e7 to 06e20ae Compare September 23, 2024 21:03
@jake-low jake-low requested a review from jschwarz2030 October 2, 2024 20:26
@CollinBeczak
Copy link
Collaborator

these are the only issues i found: #2459

@jake-low jake-low merged commit 2798f86 into main Oct 3, 2024
6 checks passed
@jake-low jake-low deleted the jlow/cleanup-sprites branch October 3, 2024 17:30
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.

2 participants