wobsoriano / svelte-sonner

An opinionated toast component for Svelte. A port of @emilkowalski's sonner.
https://svelte-sonner.vercel.app
593 stars 18 forks source link

reduce size (adds 110kb to bundle) #103

Open mustafa0x opened 2 months ago

mustafa0x commented 2 months ago

First, thanks for svelte-sonner. It's quite a nice toast component.

Second, I replaced my hand rolled toast component with sonner, and saw bundle.es.js grow by 110kb (50kb after minifying). I didn't expect such an increase!

I diffed the bundles to see if there was a single culprit. However it was mostly the generated svelte code for the sonner component. So there doesn't seem to be any simple fix to this problem.

I copied the added code to a gist (4k lines!), for whomever is curious to see what was added.

o-az commented 1 month ago

I noticed this too and ended up replacing with svelte-french-toast

mustafa0x commented 1 month ago

It's quite confusing to me. There's no clear culprit, other than the generated code being huge. There are a few things that would help (eg extracting out the svg, or making it a raw string), but no clear low hanging fruit.

I think Svelte 5 will reduce the bundle size a fair bit.

o-az commented 1 month ago

replacing svgs with <img src="path/to/svg-file.svg" /> would definitely reduce bundle size

mustafa0x commented 1 month ago

My app

$> du -hs dist/{bundle.es.js,bundle-final.js}
216K  dist/bundle.es.js
96K   dist/bundle-final.js

After adding svelte-french-toast.

$> du -hs dist/{bundle.es.js,bundle-final.js}
280K  dist/bundle.es.js
116K  dist/bundle-final.js

So it adds 64k, and 20k minified. A lot more reasonable.

mustafa0x commented 5 days ago

I think Svelte 5 will reduce the bundle size a fair bit.

250.80 kB with, 191.62 kB without (minified: 102.6 kB / 79 kB). So around 50% less than svelte 4.

Which is a lot better. 24kb minified is still a bit on the larger side though.