Svelte Explained

Svelte
Svelte
Logo Upright:yes
Author:Rich Harris
Developer:The Svelte contributors. Key contributors include Rich Harris, Alan Faubert, Tan Li Hau, Ben McCann, and Simon Holthausen
Platform:Web platform
Genre:Web framework
License:MIT License

Svelte is a free and open-source component-based front-end software framework, and language[1] created by Rich Harris and maintained by the Svelte core team members.

Svelte is not a monolithic JavaScript library imported by applications: instead, Svelte compiles HTML templates to specialized code that manipulates the DOM directly, which may reduce the size of transferred files and give better client performance. Application code is also processed by the compiler, inserting calls to automatically recompute data and re-render UI elements when the data they depend on is modified. This also avoids the overhead associated with runtime intermediate representations, such as virtual DOM, unlike traditional frameworks (such as React and Vue) which carry out the bulk of their work at runtime, i.e. in the browser.[2] [3] [4] [5] [6] [7]

The compiler itself is written in JavaScript.[8] [5] Its source code is licensed under MIT License and hosted on GitHub.[5] Among comparable frontend libraries, Svelte has one of the smallest bundle footprints at merely 2KB.[9]

History

The predecessor of Svelte is Ractive.js, which Rich Harris created in 2013.[10]

Version 1 of Svelte was written in JavaScript and was released on 29 November 2016.[11] The name Svelte was chosen by Rich Harris and his coworkers at The Guardian.

Version 2 of Svelte was released on 19 April 2018. It set out to correct what the maintainers viewed as mistakes in the earlier version such as replacing double curly braces with single curly braces.

Version 3 of Svelte was written in TypeScript and was released on 21 April 2019. It rethought reactivity by using the compiler to instrument assignments behind the scenes.

The SvelteKit web framework was announced in October 2020 and entered beta in March 2021.[12] [13]

Version 4 of Svelte was released on 22 June 2023. It was a maintenance release, smaller and faster than version 3.[14] A part of this release was an internal rewrite from TypeScript back to JavaScript, with JSDoc annotations.[8] This was met with a confusion from the developer community, which was addressed by the creator of Svelte, Rich Harris.[15] [16]

Version 5 of Svelte was released on October 19, 2024. It was a ground-up rewrite of Svelte, changing core concepts such as reactivity and reusability.[17] Its primary feature, runes, reworked how reactive state is declared and used. Runes are function-like macros that are used to declare a reactive state, or code that uses reactive states. These runes are used by the compiler to indicate values that may change and are depended on by other states or the DOM.[18] Svelte 5 also introduces Snippets, which are reusable "snippets" of code that are defined once and can be reused anywhere else in the component.[19] Svelte 5 was initially met with controversy due to its many changes, and thus deprecations caused primarily by runes.[20] However, most of this has subsided since the initial announcement of runes, and the further refining of Svelte 5.

Key early contributors became involved with Conduitry joining with the release of Svelte 1, Tan Li Hau joining in 2019, and Ben McCann joining in 2020. Rich Harris and Simon Holthausen joined Vercel to work on Svelte fulltime in 2022.[21] Dominic Gannaway joined Vercel from the React core team to work on Svelte fulltime in 2023.[22]

SvelteKit 1.0 was released in December 2022 after two years in development.[23]

Syntax

Svelte applications and components are defined in files, which are HTML files extended with templating syntax that is based on JavaScript and is similar to JSX.

Svelte's core features are accessed through runes, which syntactically look like functions, but are used as macros by the compiler. These runes include:

Additionally, the { {{var|JavaScript code}} } syntax can be used for templating in HTML elements and components,[24], similar to template literals in JavaScript. This syntax can also be used in element attributes for uses such as two-way data binding, event listeners, and CSS styling. A Todo List example made in Svelte is below:

Todo List/



Associated projects

SvelteKit
SvelteKit
Platform:Web platform
Genre:Web framework
License:MIT License

The Svelte maintainers created SvelteKit as the official way to build projects with Svelte. It is a Next.js-style framework that dramatically reduces the amount of code that gets sent to the browser. The maintainers had previously created Sapper, which was the predecessor of SvelteKit.[25]

The Svelte maintainers also maintain a number of integrations for popular software projects under the Svelte organization including integrations for Vite, Rollup, Webpack, TypeScript, VS Code, Chrome Developer Tools, ESLint, and Prettier.[26] A number of external projects such as Storybook have also created integrations with Svelte and SvelteKit.

Influence

Vue.js modeled its API and single-file components after Ractive.js, the predecessor of Svelte.

Adoption

Svelte is widely praised by developers. Taking the top ranking in multiple large scale developer surveys, it was chosen as the Stack Overflow 2021 most loved web framework and 2020 State of JS frontend framework with the most satisfied developers.[27] [28]

Svelte has been adopted by a number of high-profile web companies including The New York Times, Apple, Spotify, Radio France (French national public radio broadcaster),[29] Square, Yahoo, ByteDance, Rakuten, Bloomberg, Reuters, Ikea, Facebook, FrontPopulaire-2024 and Brave.[30] [31] [32]

A community group of non-maintainers, known as the Svelte Society, run the Svelte Summit conference, write a Svelte newsletter, host a Svelte podcast, and host a directory of Svelte tooling, components, and templates.[33]

See also

Notes and References

  1. Web site: Harris . Rich . 2018-11-26 . The truth about Svelte . 2022-12-21 . GitHub Gist . en-US.
  2. Web site: React vs. Svelte, the JavaScript build-time framework . react-etc.net.
  3. Web site: Svelte 3 Front-End Framework Moves Reactivity into the JavaScript Language, Q&A with Rich Harris . InfoQ.
  4. Web site: Slim, speedy Svelte framework puts JavaScript on a diet . Paul . Krill . December 2, 2016 . InfoWorld.
  5. Web site: GitHub - sveltejs/svelte: Cybernetically enhanced web apps . January 11, 2020 . GitHub.
  6. Web site: 2019-04-22 . Rich Harris . Svelte 3: Rethinking reactivity . 2021-08-07 . svelte.dev . en.
  7. Web site: 2018-12-27 . Rich Harris . Virtual DOM is pure overhead . svelte.dev . en.
  8. Web site: TS to JSDoc Conversion #8569 . GitHub.com.
  9. Web site: 2023-08-01 . Frontendeng.dev . Svelte vs React: Which framework is better? . frontendeng.dev . en.
  10. Web site: 2020-11-19 . About the Svelte JavaScript framework . Świstak, Tomasz . https://web.archive.org/web/20220327064110/https://valuelogic.one/blog/the-rise-of-the-svelte-javascript-framework/ . 2022-03-27 . 2021-06-10 . Blog . ValueLogic . en-US . By the way, Vue’s syntax has been influenced by Ractive.js, a direct predecessor of Svelte..
  11. Web site: Svelte Origins: A JavaScript Documentary . YouTube . en . 2022-07-09.
  12. Web site: Rich Harris: Futuristic Web Development . YouTube . https://ghostarchive.org/varchive/youtube/20211212/qSfdtmcZ4d0 . 2021-12-12 . live . en . 2021-08-03.
  13. Web site: Harris . Rich . 2021-03-23 . SvelteKit is in public beta . 2021-08-03 . svelte.dev . en-US.
  14. Web site: team . The Svelte . 2023-06-22 . Announcing Svelte 4 . 2023-08-08 . svelte.dev . en.
  15. Web site: TS to JSDoc Conversion . Hacker News (news.ycombinator.com) . 2023-05-10.
  16. Web site: Lordy, I did not expect an internal refactoring PR to end up #1 on Hacker News. ... . Hacker News (news.ycombinator.com) . 2023-05-10.
  17. Web site: Svelte 5 is alive . svelte.dev.
  18. Web site: Introducing runes . svelte.dev.
  19. Web site: . Docs . svelte.dev.
  20. Web site: Svelte 5 is React, and I wanna cry . r/sveltejs . reddit.com.
  21. Web site: Harris . Rich . Nov 11, 2021 . today is a big day for @sveltejs: i've joined @vercel to work on it full time! . 2022-09-04 . Twitter . en-US.
  22. Web site: https://twitter.com/trueadm/status/1640761270566633472 . 2023-09-30 . X (formerly Twitter) . en.
  23. Web site: 2022-12-14 . Accouncing SvelteKit 1.0 . 2022-12-16.
  24. Web site: Svelte tutorial page . svelte.dev . 2022-07-06.
  25. Web site: Harris . Rich . December 31, 2017 . Sapper: Towards the ideal web app framework . 2022-11-29 . svelte.dev . en-US.
  26. Web site: Svelte . 2021-08-03 . GitHub . en-US.
  27. Web site: Stack Overflow Developer Survey 2021 . 2021-10-26 . . en-US.
  28. Web site: State of JS 2020: Front-end Frameworks . 2021-10-26 . 2020.stateofjs.com . en.
  29. Web site: Radio France migrated their site to SvelteKit . 2024-06-04 . reddit.com . en-US.
  30. Web site: Svelte • Cybernetically enhanced web apps . 2021-08-03 . svelte.dev . en-US.
  31. Web site: Websites using Svelte - Wappalyzer . 2021-08-03 . www.wappalyzer.com.
  32. Web site: Your Profile, Your Home Experience . 2021-12-01 . yourhome.fb.com . en-US.
  33. Web site: Home - Svelte Society . 2021-08-03 . sveltesociety.dev . en.