Closed BinaryIgor closed 1 month ago
It seems like you're encountering a significant amount of network load when using Shoelace components via CDN. Even though you're cherry-picking individual components, the number of requests and the size of data being fetched remain substantial. This is a common issue when using CDN-hosted web components like Shoelace, especially if the components have many dependencies or include polyfills for browser compatibility.
Bundle the components: Instead of loading each component separately from the CDN, consider bundling them into a single file using a module bundler like Webpack or Rollup. This can significantly reduce the number of requests.
Use a Local Copy: Instead of loading the Shoelace components from a CDN, you could download the necessary components and host them locally. This allows more control over what's being loaded and reduces the need for repeated requests to the CDN.
`<!DOCTYPE html>
`
The advice above is sound. The CDN + autoloader is the quickest and easiest way to get started. For advanced usage and the most compact bundle size/low requests possible, use a bundled and self host it.
closing as this is by design
Got you, but unfortunately with bundler size is also rather significant - still a few hundred kilobytes. I just think that something is bundled/minified in the Sholeace itself incorrectly.
Using similar setup to the official example:
import '@shoelace-style/shoelace/dist/themes/light.css';
// import '@shoelace-style/shoelace/dist/themes/dark.css';
import SlButton from '@shoelace-style/shoelace/dist/components/button/button.js';
import SlIcon from '@shoelace-style/shoelace/dist/components/icon/icon.js';
import SlInput from '@shoelace-style/shoelace/dist/components/input/input.js';
import SlRating from '@shoelace-style/shoelace/dist/components/rating/rating.js';
import SlSelect from '@shoelace-style/shoelace/dist/components/select/select.js';
import SlOption from '@shoelace-style/shoelace/dist/components/option/option.js';
import SlTextarea from '@shoelace-style/shoelace/dist/components/textarea/textarea.js';
import SlDialog from '@shoelace-style/shoelace/dist/components/dialog/dialog.js';
import { setBasePath } from '@shoelace-style/shoelace/dist/utilities/base-path.js';
// Set the base path to the folder you copied Shoelace's assets to
setBasePath('/dist/shoelace');
My bundle size is almost 300 KB:
I understand that the smallest possible bundle size might not by a priority of the Web Components library but a few hundred kilobytes, for just a few components suggests to me that something went wrong while bundling them - it's way too much, I would expect 1/4 or 1/5 of this size.
@BinaryIgor you have a repository you can share? There's a few things that can be causing this, but I need a reproduction to be able to know for sure.
Yes, it's a little intermingled with other things but you should be able to reproduce it by following from here: https://github.com/BinaryIgor/code-examples/tree/web-components-experiments/htmx-shoelace-app/static
@KonnorRogers were you able to take a look?
@BinaryIgor yes.
So your example isn't Gzipping the components which is probably inflating the number more than you would expect.
With gzip enabled that size goes from 288kb uncompressed down to 63kb compressed with gzip
, probably even smaller with Brotli.
Got you; I am aware of this and was just thinking that they should be smaller even without compression. Thanks!
@BinaryIgor part of it is that <sl-select>
is probably the biggest component because it's composed of many other shoelace components , used floating UI, etc.
iirc when I removed the select it accounted for almost half the size of the JS you see.
First of all, thank you for this amazing library!
Describe the bug
By using CDN and cherry picking components, I still see rather significant network load; dozens of requests are made and hundreds of kilobytes are being fetched.
To Reproduce
Create empty HTML page with shoelace css and a few CDN components like this:
Expose it on the local HTTP server and check out network tab in the browser to see network activity.
Screenshots
I've exposed the above HTML on HTTP server locally; here's definitely too high network activity I'm talking about (lots of requests, lots of data for just a few components):