0
0
Svelteframework~5 mins

Page load functions (+page.js) in Svelte - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of a +page.js file in SvelteKit?
The +page.js file defines a page load function that runs before the page renders. It fetches data or prepares props for the page component.
Click to reveal answer
beginner
How do you export a load function in +page.js?
You export a named async function called <code>load</code>. For example: <pre>export async function load({ params, fetch }) { /* ... */ }</pre>
Click to reveal answer
intermediate
What arguments does the load function receive in +page.js?
It receives an object with properties like params (route parameters), fetch (to make requests), url (current URL), and route (route info).
Click to reveal answer
beginner
What should the load function return in +page.js?
It should return an object with data that becomes props for the page component. For example:
return { user, posts }
Click to reveal answer
intermediate
Can the load function in +page.js run on the server, client, or both?
By default, it runs on the server during initial page load. It can also run on the client during navigation between pages.
Click to reveal answer
What does the load function in +page.js primarily do?
ADefines CSS styles for the page
BFetches data before the page renders
CHandles user input events
DManages routing configuration
Which of these is NOT a parameter passed to the load function?
Adocument
Bfetch
Cparams
Durl
What must the load function return?
ANothing, it returns void
BA string with HTML content
CA boolean indicating success
DAn object with data for the page
Where does the load function run when you first visit a page?
AOnly on the server
BOnly in the browser console
COn both server and client simultaneously
DOnly on the client
How do you export the load function in +page.js?
Aexport default function load() {}
Bfunction load() {}
Cexport async function load() {}
Dmodule.exports = load
Explain how the load function in +page.js helps prepare data for a SvelteKit page.
Think about when and why you need data ready before showing a page.
You got /4 concepts.
    Describe the difference in where the load function runs during initial page load versus client-side navigation.
    Consider server rendering and client navigation separately.
    You got /4 concepts.