Header - Liquid Tag Reference
On this page
The header simple tag sets HTTP response headers from within a Liquid template. Use it to control caching behavior, content security policies, search engine indexing, and other response headers sent to the browser.
Syntax
```liquid
{% header name: “Header-Name”, value: “header-value” %} ```
| Property | Value |
|---|---|
| Tag name | header |
| Type | Simple tag |
| Source | Hydrofoil (core) |
Parameters
| Parameter | Required | Type | Description |
|---|---|---|---|
name |
Yes | String | The HTTP header name (e.g. Cache-Control, X-Custom-Header). |
value |
Yes | String | The header value. Can be a static string or a Liquid variable. |
Description
When a page renders, StoreConnect collects all header tags encountered in the template and includes them in the HTTP response sent to the browser. If multiple tags set the same header name, the last value wins (overwrites earlier ones).
Some platform-level headers like Content-Type and Set-Cookie are controlled by StoreConnect and cannot be overridden.
For comprehensive examples, use cases, and patterns, see Liquid header tag.
Where you can use it
The header tag works in all template contexts:
- Layout templates (layouts/)
- Page templates (pages/)
- Snippets (snippets/)
- Database content blocks (content stored in Salesforce)
Headers set in any of these contexts are merged into the final HTTP response.
Common uses
| Use case | Header | Example |
|---|---|---|
| Prevent search indexing | X-Robots-Tag |
noindex, nofollow |
| Control browser caching | Cache-Control |
max-age=3600 |
| Prevent clickjacking | X-Frame-Options |
SAMEORIGIN |
| Control referrer leakage | Referrer-Policy |
strict-origin-when-cross-origin |
| Content security policy | Content-Security-Policy |
frame-ancestors 'self' |
| Custom headers | X-Custom-* |
Any app-specific header |
Examples
Prevent a page from being indexed
```liquid
{% if current_page.identifier == “draft-content” %} {% header name: “X-Robots-Tag”, value: “noindex” %} {% endif %} ```
Set caching headers from a layout
```liquid
{% header name: “Cache-Control”, value: “public, max-age=86400” %} ```
Set multiple headers
```liquid
{% header name: “X-Frame-Options”, value: “SAMEORIGIN” %} {% header name: “Referrer-Policy”, value: “strict-origin-when-cross-origin” %} {% header name: “Permissions-Policy”, value: “geolocation=(), microphone=()” %} ```
Use a variable in the header value
```liquid
{% header name: “X-Store-Region”, value: current_store.name %} ```
Conditional headers based on authentication
```liquid
{% if current_customer %} {% header name: “Cache-Control”, value: “private, max-age=0” %} {% else %} {% header name: “Cache-Control”, value: “public, max-age=3600” %} {% endif %} ```
This tells the browser not to cache pages for logged-in users (since prices, inventory, and account-specific content change per customer), but allows caching for anonymous visitors.
Notes
- Multiple calls with the same name: If you set
X-Custom-Headertwice in the same template, the last value is used. - Header values are visible to clients: Do not use headers to transmit secrets or sensitive information. Headers appear in browser dev tools and response logs.
- Dynamic values are supported: You can pass Liquid variables in the
valueparameter. The variable is evaluated at render time. - Platform headers are read-only: StoreConnect controls
Content-Type,Content-Length,Set-Cookie, and other core HTTP headers. Attempting to override them has no effect.
Was this article helpful?
Thanks for your feedback! It helps us improve our docs.