SvelteKit 1.0 Officially Released: A New Way to Build Web Applications

2 min

SvelteKit 1.0 Is Here!

In December 2022, the Svelte team officially announced the release of SvelteKit 1.0. It was a milestone for both the Svelte community and the wider frontend field. SvelteKit is no longer merely “Next.js or Nuxt.js for Svelte.” It brings its own distinctive design philosophy and aims to offer a simpler, more flexible, and higher-performance way to build Web applications.

What Is SvelteKit?

If you are familiar with Svelte, you probably know that Svelte itself is a component framework. Through a radical compiler, it transforms your .svelte files into efficient imperative JavaScript at build time, achieving remarkable performance and extremely low runtime overhead.

SvelteKit, meanwhile, is an application framework built on top of Svelte. It handles everything needed to build a complete application—routing, server-side rendering (SSR), data loading, deployment adapters, and more—so that you can focus on developing the business logic.

Overview of Core Features

1. Filesystem-Based Routing

Like Next.js, SvelteKit automatically generates routes from the structure of your file system. The file structure under src/routes maps directly to the application’s URLs.

  • src/routes/+page.svelte -> /
  • src/routes/about/+page.svelte -> /about
  • src/routes/blog/[slug]/+page.svelte -> /blog/some-post

This convention-over-configuration approach greatly simplifies route management.

2. Flexible Rendering Modes

SvelteKit lets you precisely control the rendering mode at the page level. Server-side rendering (SSR), static site generation (SSG), or a hybrid of the two can all be implemented in the same application. You can even disable SSR for a single page and turn it into a purely client-side single-page application (SPA).

3. The Universal load Function

SvelteKit unifies the data-loading model. Alongside each page or layout, you can create a +page.js or +page.server.js file and export a load function.

  • In +page.js, the load function runs on both the server and the client.
  • In +page.server.js, the load function runs only on the server, so you can safely access a database or private API there.

The data returned by the load function is automatically passed to the corresponding +page.svelte component.

// src/routes/blog/[slug]/+page.server.js
import * as db from '$lib/server/database';

export async function load({ params }) {
  const post = await db.getPost(params.slug);
  return { post };
}

4. Adapters

“Write once, deploy anywhere” is one of SvelteKit’s core promises. Through adapters, SvelteKit can package your application in the format required by any target platform.

  • @sveltejs/adapter-node: For deployment to a traditional Node.js server.
  • @sveltejs/adapter-vercel: Adapts the application for the Vercel platform.
  • @sveltejs/adapter-static: Prerenders the entire application as static files suitable for any static host.
  • More official and community adapters are available for platforms such as Netlify and Cloudflare Workers.

Conclusion

The release of SvelteKit 1.0 marked the maturity of the Svelte ecosystem. It combines the exceptional performance of the Svelte compiler with a carefully designed application framework, providing developers with a powerful and enjoyable development experience. If you are looking for a versatile framework that can build anything from simple static pages to complex dynamic applications, SvelteKit is certainly worth trying.