在 load
函数中(以及 表单操作、hooks 和 API 路由,我们稍后会了解),你可以访问 setHeaders
函数,不出所料,该函数可用于设置响应的标头。
¥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.
最常见的是,你会使用它来通过 Cache-Control
响应标头自定义缓存行为,但为了本教程的目的,我们将做一些不太可取且更具戏剧性的事情:
¥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'
});
}
(你可能需要重新加载 iframe 才能看到效果。)
¥(You may need to reload the iframe to see the effect.)
上一页 下一页
1
<h1>hello world</h1>