最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Svelte multiple small components vs regular html elements - Stack Overflow

programmeradmin5浏览0评论

Does it affect performance having svelte components instead of regular HTML elements, for small things like buttons, links etc?

Wrapping these elements in a svelte component would make it more convenient in code, but if it adds a lot of overhead then it may not be worth it.

Does it affect performance having svelte components instead of regular HTML elements, for small things like buttons, links etc?

Wrapping these elements in a svelte component would make it more convenient in code, but if it adds a lot of overhead then it may not be worth it.

Share Improve this question asked Mar 26 at 18:58 AlexAlex 66.1k185 gold badges459 silver badges651 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

There are two things that cause some overhead here:

  • The general Svelte runtime (managing reactivity, effects, rendering)
  • The generated component code

If you are using client-side functionality of Svelte at all, the runtime has to be loaded. The relative cost of this goes down with the number of component definitions since the runtime is shared.

The overhead for the component code also amortizes with the number of component instances, since they all share the same definition. So if you only have one or very few instances, it might make a noticeable difference in the bundle sizes but for any sufficiently complex application, I would not worry about this.

The code of simple wrapper components will share similarities which also helps if the code is transferred gzipped.

发布评论

评论列表(0)

  1. 暂无评论