resources.html (外部連結) home.headers (外部連結)
Headers are the HTTP response headers a server sends along with its response to the browser. Yore includes a default headers template. When you enable it, Yore generates a _headers file.
Before you begin 此標題的連結
- The
_headersfile works only on Netlify and Cloudflare. - Most sites don't need custom headers. Enable this feature only when you know why you need it.
Configuration 此標題的連結
Add headers to outputs.home to enable the default template:
hugo.yaml
outputs:
home:
# Your existing output formats
- html
- rss
# Add this line
- headersWhat the template does 此標題的連結
The default template (外部連結) provides the following:
- Sets
charset=utf-8for Markdown files so browsers don't display garbled text. - Enables a strict Content Security Policy (CSP).
- Adds common security headers that enforce HTTPS, stop browsers from guessing file types, restrict embedding your site in other sites, and disable camera, microphone, geolocation, and payment permissions.
How strict CSP affects your site 此標題的連結
A strict CSP limits what your site can load:
- Inline scripts are blocked, and you can't insert script nodes dynamically with JavaScript.
- Scripts can come only from your own site and specific CDNs.
- Iframes are allowed only for Giscus and YouTube.
- Other restrictions also apply.
If you add your own inline scripts or content from other sources, the browser refuses to load them.
Yore is a purely static site, so a strict CSP offers limited practical benefit. If your site doesn't need to pass a strict security audit, don't enable the headers feature.