Skip to main content
Bases de Svelte
Introduction
Réactivité
Props
Logique
Events
Bindings
Classes and styles
Actions
Transitions
Advanced Svelte
Advanced reactivity
Reusing content
Motion
Advanced bindings
Advanced transitions
Context API
Special elements
<script module>
Next steps
Basic SvelteKit
Introduction
Routing
Loading data
Headers and cookies
Shared modules
Forms
API routes
$app/state
Errors and redirects
Advanced SvelteKit
Hooks
Page options
Link options
Advanced routing
Advanced loading
Environment variables
Conclusion

Inside a load function (as well as in form actions, hooks and API routes, which we’ll learn about later) you have access to a setHeaders function, which — unsurprisingly — can be used to set headers on the response.

Most commonly, you’d use it to customise caching behaviour with the Cache-Control response header, but for the sake of this tutorial we’ll do something less advisable and more dramatic:

src/routes/+page.server
export function load({ setHeaders }) {
	setHeaders({
		'Content-Type': 'text/plain'
	});
}

(You may need to reload the iframe to see the effect.)

Modifier cette page sur Github

1
<h1>hello world</h1>