Svelte
About SVELTE?
![](https://user-images.githubusercontent.com/70523057/136572595-f97910e5-3cbc-473a-937f-aaf948cb3d29.png)
Instead of using techniques like virtual DOM diffing, Svelte writes code that surgically updates the DOM when the state of your app changes.
Svelte was recently voted the with the most loved web framework in most experienced developers a pair of industry surveys.
What is SVELTE?
- Svelte is a free and open-source front end tool for building fast web applications.
- It is similar to JavaScript frameworks such as React and Vue, which share a goal of making it easy to build slick interactive user interfaces.
- But there's a crucial difference:
- Svelte converts your app into ideal JavaScript at build time, rather than interpreting the application code at run time.
- This is the reason we don't pay the performance cost of the framework's abstractions, and we don't incur a penalty when the app first loads.
- You can build your entire app with Svelte, or you can add it incrementally to an existing codebase.
- You can also ship components as standalone packages that work anywhere, without the overhead of a dependency on a conventional framework.
- In Svelte, an application is composed from one or more components. A component is a reusable self-contained block of code that encapsulates
HTML
,CSS
andJavaScript
that belong together, written into a.svelte
file.
How its works?
Most front-end frameworks rely on a diffing engine that syncs the visual DOM with an in-memory copy of the DOM.
Svelte is different. It's a compiler. It generates code (JavaScript) that updates the visual tree directly, without diffing.
Think of it as converting html like <h1>Hello World</h1>
into:
const element = document.createElement('h1')
element.textContent = "Hello World"
document.body.appendChild(element)
Now, why would you want to do that? Because of data binding.
It means we can write <h1>{someValue}</h1>
declaratively and and we don't need to write imperative statements like element.textContent = someValue
every time someValue changes.
Svelte generates the synchronization code for us.
The compiler takes in .svelte
files, parses them into an AST Abstract Syntax Tree, analyzes the tree, and generates Javascript and CSS.
You can try the Online Svelte Compiler
![](https://user-images.githubusercontent.com/70523057/136598955-6fff83f0-cded-43a0-a752-88d038cd291b.png)