Export storefront managers often struggle with balancing page load speed against the risk of serving outdated content. This article addresses how to correctly set Cache-Control headers on static assets using standard web server configurations. We will explore the fundamental concepts of caching, specific directive syntax for Apache and Nginx, and practical methods for verifying that your configuration behaves as intended.

Scenario: A Storefront Manager Updating Static Asset Policies

This is a hypothetical example, not a recommendation list or a record of a real deployment. Picture a storefront manager at a small export business who has inherited a static site: a home page, six product category pages, a handful of catalog PDFs, and a few hundred product images. The site is served from a single origin and the content changes only when a new catalog is published, roughly once a quarter.

The manager opens a spreadsheet and sketches three policy groups with plain names she understands. She labels them "Shell pages," "Versioned media," and "Live pages." Under "Shell pages" she lists the home page and category pages: cacheable for a short window, with a directive requiring revalidation before reuse. Under "Versioned media" she lists catalog files whose names carry a quarter code, such as catalog-2025-Q1.pdf, and product images whose names carry a size and revision suffix, such as pump-800w-r2.jpg. These get a long max-age, because a new edition arrives under a new name rather than overwriting the old file. Under "Live pages" she lists a stock-status page and an inquiry form page, which she marks as not cacheable at all.

She writes two fictional sample rows to show how the sheet is used. Row one: path /catalog/catalog-2025-Q1.pdf, group Versioned media, change date 2025-01-15, new name on revision, old name kept for one quarter. Row two: path /stock/status, group Live pages, change date none planned, revalidate on every request, owner the warehouse desk. A third row for /category/pumps lands in Shell pages with a fifteen-minute freshness window and a note that publishing a new catalog triggers a rename rather than an overwrite.

Then she makes one deliberate trade-off. For the category pages she chooses a short freshness window over immediate purge, reasoning that a quarter-hour delay in showing a new catalog banner is acceptable, while an uncached first visit to a category page on a slow connection is not. She notes this reason in the spreadsheet so a colleague can revisit it. Nothing here has been tested; the groups and rows are her own working fiction for organizing questions before she touches any server configuration.

Understanding Core Caching Concepts and Freshness

RFC 9111 treats caching as an optional HTTP feature that reuses a prior response to satisfy a current request, and defines a cache as a local store of response messages plus the subsystem that controls storage, retrieval, and deletion. A stored response counts as fresh when it can be reused without validation, so a fresh response can reduce both latency and network overhead on each reuse. A shared cache stores responses for reuse by more than one user and is usually deployed as part of an intermediary; a private cache is dedicated to a single user and is often a component of a user agent.1

Storage is conditional. A cache must not store a response unless the request method is understood, the status code is final, and the response contains at least one of the listed signals, such as a public or private directive, an Expires header field, max-age, s-maxage for a shared cache, or a heuristically cacheable status code.1

You can take your own asset inventory and mark each item as one of three working groups: shell pages, versioned media, or live pages. For a catalog PDF you rename with each release, note the filename and the release date in the same row, then write the freshness as a long window because the path itself changes when the file changes. For a category page whose wording you sometimes edit in place, note the path and the last edit date, and consider a short window so visitors see the update without a manual purge.

You might fill two sample rows in your own notes. First row: path /catalog/catalog-2025-Q1.pdf, group versioned media, change date 2025-01-15, freshness long. Second row: path /products/ceramics, group live page, change date 2025-02-03, freshness short. The same fields work for an archived notice: path /notices/2024-price-update, group archived, change date 2024-12-01, freshness long, marked archival in the notes column. Filling the archival row beside the current one lets you see at a glance which entries you intend to keep stable and which you expect to revisit.

For one category page, you might deliberately choose a short freshness window over immediate purge, accepting a brief delay in exchange for fewer manual steps. Whether that trade suits your catalog cycle is your call; record the reason next to the row so a later reader can follow it.

Configuring Cache-Control Headers in Apache mod_headers

Apache mod_headers provides the Header directive to configure HTTP response headers, with the syntax Header [condition] add|append|merge|set|unset header value. For a 200 response, the Apache 2.4 documentation's example appends a caching header by pairing the directive with an expression: Header append Cache-Control s-maxage=600 "expr=%{REQUEST_STATUS} == 200".2

The action matters. append adds a value to an existing header of the same name, separated by a comma, while merge adds the value only if it does not already appear in that header's comma-delimited list.2

Conditions can restrict when a directive applies. The env argument applies it only if the named environment variable exists, and expr applies it only if the expression evaluates to true.2

Take your asset inventory and rule notes, then draft the mod_headers lines you would actually apply for one group before touching any other. You can write them as plain text in your own notes first: for the versioned catalog PDF group, a line matching that path with a long freshness value and a public cache setting. Read the line back against the sheet and check that the path, the group name, and the freshness choice agree.

For the shell pages group, you might draft a separate line with a shorter window and no long-lived marker, then compare the two drafts side by side. That comparison is your decision point: does each line match the change date you recorded, or does it promise freshness longer than the content really holds? You can rewrite either line once before considering it settled.

If a line feels wrong, change one element at a time — the path match or the freshness value — and note why in the sheet. Keeping the draft, the revision, and the reason together lets you revisit the choice after the next catalog publication without starting over.

Setting Expiration Times with Nginx ngx_http_headers_module

The ngx_http_headers_module lets you add Expires and Cache-Control fields to response headers, using the expires directive alongside add_header. The expires directive applies only when the response code equals 200, 201, 204, 206, 301, 302, 303, 304, 307, or 308. The header value follows the sign of the time: a negative time produces Cache-Control: no-cache, while a positive or zero time produces Cache-Control: max-age=t, with t in seconds. The epoch parameter sets Expires to the 1970 value and Cache-Control to no-cache; max sets Expires to the December 2037 value and Cache-Control to 10 years.3

The modified parameter computes expiry from the file's modification time plus the specified time. A time of day can be set with the @ prefix. The final parameter value can contain variables, as in a map that returns 42d for application/pdf and max for image types, then passes that variable to expires. The add_header directive adds a named field only for its listed response codes unless the always parameter is given, and values may contain variables; inheritance from a previous level applies only when no add_header directives are defined at the current level.3

You can draft the corresponding header lines in parallel from the same inventory rather than editing one and copying later. Write your shell page line with the shorter lifetime, and a separate line for the versioned media you identified. When you compare the two, check that each path match or location selector points at the group you mean, and that the lifetime value matches what your sheet records for that group.

For one concrete rehearsal, take the catalog spreadsheet row you already filled—path /catalog/catalog-2025-Q1.pdf, group versioned media, change date 2025-01-15—and write a draft line that pairs that route with a long lifetime. Then write a second draft for your home page with a short lifetime and no long-lived marker. Read them side by side as plain text before applying either, keeping both drafts in your notes with the reason for the difference in lifetime values. This is a hypothetical comparison, not a record of any deployment.

If the pair still feels unclear, you can change one element at a time—the route match or the lifetime—and record why in the sheet, so a later quarter's self-review can trace the decision back to a specific asset and date.

Verifying Header Output and Debugging Common Errors

Verification against the Apache HTTP Server mod_headers documentation begins with the module's own warning: add puts the response header into the existing set even if a header of that name already exists, which can produce two or more headers with the same name and lead to unforeseen consequences. The documentation states that set, append or merge should generally be used instead. It also says that specifying always includes the header in non-2xx responses such as redirects or errors, and it calls the difference between always and onsuccess a frequent source of confusion.4

For a directive the module itself added, the condition parameter must match the one originally used. Otherwise, the documentation says to determine by trial and error whether always is needed, because you cannot reliably know which internal table holds the existing value. For merge, values are compared case sensitively after format specifiers are processed, and values in double quotes count as different from otherwise identical unquoted values.4

For your own rehearsal, you can set up a small comparison record rather than trusting a header draft by feel. Take the catalog row you have already sketched and write two candidate notes beside it: one for the versioned catalog file with a long freshness value, and one for a category page with a short window. Then list what you expect a visitor or search engine to see for each before any server change; a later check can compare that expectation against the actual response.

You might then add a debugging column to the same table and fill it with likely symptoms tied to your own lines. A stale catalog download suggests the versioned path or the long freshness marker does not match the file you replaced. A frequently vanishing promotion banner suggests the short window sits on a page that needs longer life, or that two lines overlap on the same route. Note which single element—route match or lifetime—you would change first, and why.

When you prepare your content refresh, you can keep a dated copy of each draft and mark which line you intend to apply to the shell page, which to versioned files, and which to live pages. If a later check shows a mismatch, the dated copy lets you tell whether the header text, the file path, or the timing of publication explains it.

Best Practices for Maintaining Consistent Cache Behavior

A practical next step is to turn your inventory and rule notes into a short quarterly review habit. You can choose a fixed date—say, the first working day after each catalog release—and on that date compare three things: your current asset groups, the header draft lines you intend to apply, and any changes to how often the catalog actually changes. If the catalog is now published twice a year instead of four times, the versioned media group can keep its long freshness setting while the live pages group may need a shorter window. The point is to let your own publishing rhythm, not a fixed rule, decide the numbers.

A simple review sheet can help. Consider columns such as “asset group,” “example path,” “last change date,” “freshness choice,” “reason for choice,” and “next review date.” A filled example might read: versioned media, /catalog/catalog-2025-Q1.pdf, 2025-01-15, long freshness, “file name changes with each release,” review 2025-07-01. A second row might read: live pages, /category/imports, 2025-02-10, short freshness, “prices and availability can shift,” review 2025-04-10. You can keep these rows in any format you find readable.

Consistency also depends on remembering why a line exists. You might add a short plain-language note beside each draft header line, such as “keeps old catalog links working” or “avoids showing last quarter’s stock count.” When you revisit the sheet months later, that note often matters more than the number itself, because it tells you whether the original concern still applies.

Finally, you can decide on one small signal to watch during each review. For versioned media, a useful question is whether files are genuinely getting new names; if you notice a PDF being overwritten under the same path, that group needs a different freshness choice. For live pages, ask whether the delay you accepted still feels acceptable. Recording the answer in the same sheet gives you a simple trail to follow next quarter.

Frequently asked questions

How can I organize my own asset inventory into three working groups?

You can take your own asset inventory and mark each item as one of three working groups: shell pages, versioned media, or live pages. For a catalog PDF you rename with each release, note the filename and the release date in the same row, then write the freshness as a long window because the path itself changes when the file changes.

What two sample rows might I fill in my own notes for a versioned catalog PDF?

You might fill two sample rows in your own notes. First row: path /catalog/catalog-2025-Q1.pdf, group versioned media, change date 2025-01-15, freshness long.

Which columns could I include in my own simple review sheet?

A simple review sheet can help. Consider columns such as “asset group,” “example path,” “last change date,” “freshness choice,” “reason for choice,” and “next review date.”