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

Loading in Clients

While discussing Creating Server Pages in the previous chapter, we covered how a load() function exported from +page.js will run on both the client and the server. When we want to ensure load is only run on the server, we move it to +page.server.js. But what if you’re trying to build an offline-ready application? You may be building a Progressive Web App (PWA), a Single-Page App (SPA), or both! For the sake of demonstration, let’s assume you want as much logic as possible to be managed on the client rather than your server. In this case, you’ll want load() functions to run on the client and not on the server. How can we do that when a load() function from +page.js runs in both environments?

Again, think back to the Creating Server Pages section in the previous chapter where we discussed page options, and you’ll remember the ssr option. When exported, this constant will disable or enable Server-Side Rendering based on the Boolean value...