Skip to main content

Headers

View SourceEdit this page (external link)
Published:

resources.html (external link) home.headers (external link)

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 Link to this heading

  • The _headers file 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 Link to this heading

Add headers to outputs.home to enable the default template:

hugo.yaml
outputs:
  home:
    # Your existing output formats
    - html
    - rss
    # Add this line
    - headers

What the template does Link to this heading

The default template (external link) provides the following:

  • Sets charset=utf-8 for 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 Link to this heading

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.

Article Connections

Accessibility settings