Book Image

SvelteKit Up and Running

By : Dylan Hildenbrand
Book Image

SvelteKit Up and Running

By: Dylan Hildenbrand

Overview of this book

The JavaScript ecosystem has grown vast, complex, and daunting for newcomers. Fortunately, SvelteKit has emerged, simplifying the process of building JavaScript-based web applications. This book aims to demystify SvelteKit, making it as approachable as it makes web app development. With SvelteKit Up and Running you’ll be introduced to the philosophy and technologies underlying SvelteKit. First, you’ll follow a standard educational programming approach, progressing to a 'Hello World' application. Next, you’ll explore the fundamental routing techniques, data loading management, and user submission, all through real-world scenarios commonly encountered in day-to-day development, before discovering various adapters employed by SvelteKit to seamlessly integrate with diverse environments. You’ll also delve into advanced concepts like dynamic route management, error handling, and leveraging SvelteKit to optimize SEO and accessibility. By the end of this book, you’ll have mastered SvelteKit and will be well-equipped to navigate the complexities of web app development.
Table of Contents (19 chapters)
1
Part 1 – Getting Started with SvelteKit
5
Part 2 – Core Concepts
10
Part 3 – Supplemental Concepts

Using Hooks

Unlike other JS frameworks that shall not be named, SvelteKit keeps the list of hooks to remember short and simple. At the time of writing, there are only two types of hooks – server hooks and shared hooks. As we have come to expect from names, they work similarly to how +page.server.js runs only on the server and +page.js runs on either the server or the client. Both server and shared hooks are placed in the src/ directory, either in src/hooks.server.js or src/hooks.client.js, depending on which environment we intend to run the hook on. We’ll break this section down into the following subsections:

  • Server hooks
  • Shared hooks

By the end of this section, you’ll be able to modify all incoming and outgoing requests to your SvelteKit applications.

Server hooks

The hooks that can only be run on the server are handleFetch() and handle(). As we would expect, handleFetch() has the ability to manipulate requests made by SvelteKit’...