Svelte vs. Vue.js

#javascript#vuejs#svelte

Svelte vs. Vue.js

Updated February 18th 2022 to reflect new features of Vue 3 and stuff I've learned from experience in the meantime.

I have been using Vue.js for client side browser stuff for a few years and I am very happy with it. However, I have been curious about Svelte for a while, and as I had an idea for a new project where Svelte might be a better fit than Vue, I decided to take a closer look.

Also, I have a number of ongoing projects in Vue 2, and with the significant breaking changes in Vue 3, now might be a good time to explore alternatives, as moving to a different framework might not be much more work than the Vue upgrades that I am facing anyway.

The following is based on my own experience with Svelte and Vue:

In favor of Svelte

In favor of Vue

Tie

Bundle size matters

Bundle size for small apps in certainly smaller with Svelte because there is no runtime.

But the bundle size grows faster for Svelte apps than for Vue apps - because the Svelte compiler adds stuff to the code (mainly for reactivity), while with Vue, code is largely left as is.

It appears that at some point around "medium sized" app, compiled Svelte apps could become bigger than Vue apps including runtime.

I recently did a small SPA (Danish budget calculator) based on Vue, and figured that it would be a nice test to convert this to Svelte. I copied the .vue files to a new Svelte project, renamed the files .svelte, and then manually massaged them into the Svelte syntax. The source code (Vue + Svelte) is available at: https://github.com/jesperhoy/Mit-Budget.dk

Minified and gzipped, the javascript for the original Vue version (https://mit-budget.dk/vue) is 9.2kb + 23.6kB Vue runtime = 32.8kB total (Note: this was based on Vue 2 - the Vue 3 runtime is significantly larger).
The Svelte version (https://mit-budget.dk/svelte) is 19.2kB.

Conclusion

Rich Harris asked the Marie Kodo inspired question "Does this code spark joy?"

Back when I discovered Vue - this really was a game changer for me - and it did spark a lot of joy :-)
I imagine many programmers feel this way when they first "get" the reactive UI model (be it in Vue, React, Angluar, etc.).

Vue still sparks joy, but Svelte does so even more :-)

I especially like the simpler and terser Svelte syntax, and not having to distribute a runtime.

Jesper Høy's
Dev Blog

  • Home (blog posts)
  • About me and this website
  • My developer tech stack
  • My favorite software
  • My favorite online services
  • Cool stuff
  • My side projects
  • Referral codes
  • Our wonderful ice horses