roast logo

_headers file

What is the _headers file?

  • A plain text file in the root of your deploy with the file name _headers.
  • Each line must either start with a / or contain a colon to separate a header field.
  • Lines starting with / represent a path and they can end in a * (wildcard)
  • Comments start with #
  • White space around or between lines is ignored so use it for readability.

Why use the _headers file?

For setting cache-control headers (i.e. long max-age or immutable), overriding content-type that is normally detected from the filename.
In other words, explicit control over the headers returned.

Example use cases

Give everything in the fonts dir a long/permanent cache

(only if you know the file at this path will never change)

  Cache-Control: public, max-age=365000000, immutable

Give a content-type to a path without an extension

(because by default Roast will return application/octet-stream for files without extension)

  content-type: application/json