flâneur — a map of the web's best reading

State management • Docs • SvelteKit

kit.svelte.dev · 3,501 words · saved by 1 readers

If you're used to building client-only apps, state management in an app that spans server and client might seem intimidating. This section provides tips for avoiding some common gotchas. Browsers are stateful — state is stored in memory as the user interacts with the application. Servers, on the other hand, are stateless — the content of the response is determined entirely by the content of the request. Conceptually, that is. In reality, servers are often long-lived and shared by multiple users. For that reason it's important not to store data in shared variables. For example, consider this code: The user variable is shared by everyone who connects to this server. If Alice submitted an embarrassing secret, and Bob visited the page after her, Bob would know Alice's secret. In addition, when Alice returns to the site later in the day, the server may have restarted, losing her data. Instead, you should authenticate the user using cookies and persist the data to a database. For the same re

State management • SvelteKit Docs Skip to main content Tutorial Packages Playground Blog On this page If you're used to building client-only apps, state management in an app that spans server and client might seem intimidating. This section provides tips for avoiding some common gotchas. Avoid shared state on the server Browsers are stateful — state is stored in memory as the user interacts with the application. Servers, on the other hand, are stateless — the content of the response is determined entirely by the content of the request. Conceptually, that is. In reality, servers are often long-

Explore this link on the map →

related reading