Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
SvelteKit Up and Running

You're reading from   SvelteKit Up and Running Leverage the power of a next-generation web framework to build high-performance web apps with ease

Arrow left icon
Product type Paperback
Published in Jul 2023
Publisher Packt
ISBN-13 9781804615485
Length 166 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Dylan Hildenbrand Dylan Hildenbrand
Author Profile Icon Dylan Hildenbrand
Dylan Hildenbrand
Arrow right icon
View More author details
Toc

Table of Contents (19) Chapters Close

Preface 1. Part 1 – Getting Started with SvelteKit
2. Chapter 1: Initial Setup and Project Structure FREE CHAPTER 3. Chapter 2: Configurations and Options 4. Chapter 3: Compatibility with Existing Standards 5. Part 2 – Core Concepts
6. Chapter 4: Effective Routing Techniques 7. Chapter 5: Deep Dive into Data Loading 8. Chapter 6: Forms and Data Submission 9. Chapter 7: Advanced Routing Techniques 10. Part 3 – Supplemental Concepts
11. Chapter 8: Builds and Adapters 12. Chapter 9: Hooks and Error Handling 13. Chapter 10: Managing Static Assets 14. Chapter 11: Modules and Secrets 15. Chapter 12: Enhancing Accessibility and Optimizing SEO 16. Index 17. Other Books You May Enjoy Appendix: Examples and Support

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’...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime