concept preload in category svelte

appears as: preload
Svelte and Sapper in Action

This is an excerpt from Manning's book Svelte and Sapper in Action.

Perhaps the most common use of module context is to define preload functions that are used to load data needed by a component in a Sapper app. You will learn about these in chapter 16.

When the server for a Sapper app is started, the code in the <script context="module"> element of all routes and all components they import is run. This provides a way to perform any necessary setup tasks, such as establishing WebSocket connections. Often a module context only defines a preload function and does not contain any code to be executed immediately.