Getting Started with Svelte and Rails 6

Nikola Đuza
6 min readOct 27, 2019

Svelte is slowly rising to fame these days and it’s getting more and more traction with new version 3 being released in April. If you’re interested in how to get started with Rails and Svelte, this is the right post for you! We’ll go through the whats, the whys, and the hows between the two.

Photo by Joanna Kosinska on Unsplash

What is Svelte?

Svelte is told to be a new kid on the block that is different from its colleagues — React and Vue.js. Key difference between the two and Svelte, is that Svelte doesn’t use virtual DOM technique to update your app when state changes. Instead, Svelte writes code that “surgically updates the DOM when the state of your app changes”. That sounds pretty assuring, but what does it really mean?

Svelte does its magic during build time, where it compiles your components into efficient JavaScript code. That compiled code makes the fewest possible DOM operations. Result of Svelte compilation is high performant imperative and pure code. You could say that Svelte is a compiler because it turns Svelte components into imperative JavaScript code.

BTW, Svelte is pronounced “svelt” and it’s an adjective meaning attractively thin, stylish and graceful.

Why use it with Rails?

--

--

Nikola Đuza

Nikola helps developers improve their productivity by sharing pragmatic advice & applicable knowledge on JavaScript and Ruby. https://pragmaticpineapple.com/ 🍍