File Structure
File names: the + means "special file"
| File | Runs where | Job |
|---|---|---|
+page.svelte | Server (first load) + browser | The page UI |
+page.server.ts | Server only | load data (DB, secrets), form actions |
+page.ts | Server + browser | load data that is safe in both places (public APIs) |
+layout.svelte | Server + browser | Shared UI (menu, footer) around pages |
+layout.server.ts | Server only | load data shared by many pages |
+server.ts | Server only | API endpoint (GET, POST), no page |
hooks.server.ts | Server only | Code on every request (auth, logging) |
.serverin the name = never sent to the browser. Safe for secrets and databases.+page.tsruns in both places, so no secrets, no DB, no Node-only modules.- Unsure which to use: choose
+page.server.ts.