What is the difference between +page.js and +page.server.js in SvelteKit?

Answer

Both are SvelteKit load function files but run in different environments. +page.js (universal load): runs on the server during SSR and in the browser during client navigation. Has access to the fetch function (a special SvelteKit fetch that can make relative requests). Cannot access server-only things like filesystem or private environment variables. Used when loading public API data. +page.server.js (server load): runs only on the server. Has access to locals (set by hooks), server-side database access, private environment variables, and cookies. Data is serialized and sent to the client. Also exports form actions for handling HTML form submissions. Can set cookies on the response. Rule of thumb: use +page.server.js for anything requiring authentication, database access, or secrets. Use +page.js for public API data that the client can also fetch during navigation.