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

Library is 64Kb, minified #16

Open
NullVoxPopuli opened this issue Sep 18, 2024 · 11 comments
Open

Library is 64Kb, minified #16

NullVoxPopuli opened this issue Sep 18, 2024 · 11 comments

Comments

@NullVoxPopuli
Copy link

NullVoxPopuli commented Sep 18, 2024

Posting from: https://bsky.app/profile/nullvoxpopuli.com/post/3l4g6z3holy27

After gzip, this library (+ dependencies) are 23kb.

This is quite hefty.

BundlePhobia: https://bundlephobia.com/package/[email protected]
image

Some of it is lit -- but a lot of it is just this component.

some questions:

  • Does it need all of lit?
  • is this library side-effect free?
    • this would allow tree-shaking of unused consts/functions/etc
    • BundlePhobia says:
      Exports analysis is available only for packages that export ES Modules and are side-effect free.
      This package [...] isn't marked side-effect free.
@stof
Copy link

stof commented Oct 25, 2024

the package is not side-effect free as it registers a custom element (well, 2 of them actually, as there is an internal one)

@niutech
Copy link

niutech commented Nov 4, 2024

Whooping 64KB of minified code for a small Baseline Status widget is over the roof. It should fit in <20KB of minified code.

@stof
Copy link

stof commented Nov 4, 2024

I think a big part of it is the string containing CSS code. A JS minifier won't be able to reduce the size of that string, which takes half of the size of the file.
A custom minification that applies a CSS minifier on the content of that string would likely reduce the size (not sure of the actual size reduction after gzip though)

@captainbrosset
Copy link

I agree this is a big problem that we need to solve. We shouldn't be imposing this performance cost to the hosting webpages.
(Out of scope for this issue, but we probably shouldn't be imposing JS at all either, and think about what a server-side rendered HTML version could be).

Looking at the code, the SVG browser icons seem to be responsible for a large portion of the total size of the source file. I'm estimating around 60% of it.
On top of this, the built version embeds Lit, which adds even more.

@captainbrosset
Copy link

captainbrosset commented Nov 5, 2024

Regarding the SVG, we need to think about simplifying them substantially. The size at which they get rendered by default is very small and doesn't warrant that much details which most users will not see.

If I save the SVG string for the Safari logo (which is the longest) as a SVG file, it comes out at 20KB!
Saving the rendered image (at its default size) as a PNG file results in a 3KB file only.
But, I can further than that: if I save the biggest possible size that the logo can be displayed at (500% zoom) as a file, and run it by sqoosh to convert it to AVIF, I get a 3KB file.

So, there really doesn't seem to be any reason for embedding those large, very detailed, SVG code lines in the component.

@niutech
Copy link

niutech commented Nov 5, 2024

@captainbrosset As for no-JS widget, Astro Embed <BaselineStatus> component is using Declarative Shadow DOM, but it can be done without DSD provided that the API optionally outputs HTML.

As for SVG optimization, there is an excellent tool SVGOMG.

@bramus
Copy link

bramus commented Nov 5, 2024

Instead of trying to wrangle the SVGs, how well do base64-encoded small PNGs do?

@captainbrosset
Copy link

Instead of trying to wrangle the SVGs, how well do base64-encoded small PNGs do?

Agreed that the SVGs are unnecessarily complex. At most we're only going to be showing these icons somewhere between 30px to 200px. At these sizes, raster images seem to be perform a lot better. In my previous comment, I tested AVIF which (even for the largest page zoom) produced a 3KB file for the Safari logo.

Someone should try to embed base64-encoded versions of these images and see what the result feels like.

@niutech
Copy link

niutech commented Nov 5, 2024

@captainbrosset As for AVIF, it's not widely supported, so I would stick with good old PNG.

For comparison, here is the optimized PNG version of Safari logo (40x40 px, 2119 B):
Safari logo.png
and here is the optimized SVG version of the same Safari logo (3360 B):
Safari logo.svg

Base64 encoding of PNG in data URI adds an overhead of 33%. SVG does not need to be Base64-encoded.

@captainbrosset
Copy link

If we can live with the fact that, at max zoom level, the optimized SVG shows some incorrect details, then I really like the idea.
image

@bramus
Copy link

bramus commented Nov 6, 2024

What about not including any images in the package itself? The data is fetched from an external endpoint anyways, so maybe the API server could also serve the logos?

(In that case, maybe also allow an option to set the baseURL for the logos, so that people can self-host the logos if they want to)

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

No branches or pull requests

5 participants