# Headers for STATIC ASSETS only.
#
# No Strict-Transport-Security here, deliberately. The Cloudflare zone setting
# (SSL/TLS -> Edge Certificates -> HSTS) adds it to EVERY response — these
# assets, the Worker's /api and /img responses, and any future subdomain.
# Repeating it here would risk a second HSTS header, and browsers honour only
# the first. See docs/SECURITY_SETUP.md section 2.
#
# Worker-generated responses do NOT inherit these — worker/lib/http.ts applies
# its own set, and the /admin pages build a stricter per-response CSP with a
# nonce. Anything added here that must also hold for API responses has to be
# added there too.

/*
  # NO Content-Security-Policy here.
  #
  # SvelteKit owns it now, in svelte.config.js under kit.csp, and emits it as a
  # <meta> tag carrying the sha256 of the one inline bootstrap script it
  # generates per page. A CSP could not live in both places: browsers enforce
  # the INTERSECTION of a header policy and a meta policy, so a
  # `script-src 'self'` header kept blocking that script no matter what the
  # meta allowed - and the whole app rendered its HTML and then failed to
  # hydrate. See the comment on kit.csp for the full reasoning.
  #
  # X-Frame-Options below is now load-bearing rather than belt-and-braces:
  # `frame-ancestors` is ignored in a meta CSP, so this is what stops framing.
  # It governs other sites framing THIS one; the Turnstile frame this site
  # embeds for the human check is allowed by the CSP's frame-src instead.
  X-Content-Type-Options: nosniff
  # Every <img> overrides this with referrerpolicy="no-referrer": the zone's
  # Hotlink Protection 403s /img/* for any Referer that is not this site, and
  # the packaged apps (which never see this file - Tauri serves their bundle)
  # would send tauri.localhost. docs/SECURITY_SETUP.md section 10.
  Referrer-Policy: strict-origin-when-cross-origin
  X-Frame-Options: DENY
  # No camera, mic, geolocation or payment anywhere in this app; deny them so a
  # future dependency cannot quietly start asking. The Turnstile frame inherits
  # this too and may log a harmless violation from inside
  # challenges.cloudflare.com; do not loosen it for that.
  Permissions-Policy: accelerometer=(), autoplay=(), camera=(), display-capture=(), encrypted-media=(), geolocation=(), gyroscope=(), magnetometer=(), microphone=(), midi=(), payment=(), usb=(), xr-spatial-tracking=()
  Cross-Origin-Opener-Policy: same-origin
  Cross-Origin-Resource-Policy: same-site

# Hashed build output is immutable by construction - the filename changes when
# the content does - so it can be cached hard, fonts included.
#
# One wart, accepted: an asset path that does not exist is answered with the
# SPA fallback (index.html, HTTP 200), and the rule below matches by PATH, so
# that HTML is cached as "immutable" too. It only happens to a tab left open
# across a deploy that then imports a chunk the deploy removed;
# hooks.client.ts reloads once, and the new HTML never names that URL again.
# Routing /_app/* through the Worker to answer 404 would cost an invocation
# per asset to fix a response nobody requests twice.
/_app/immutable/*
  Cache-Control: public, max-age=31536000, immutable

# Workbox's runtime is emitted as workbox-<hash>.js beside sw.js: hashed too.
/workbox-*
  Cache-Control: public, max-age=31536000, immutable

# Art and the manifest change rarely but keep their names, so they are NOT
# immutable: fresh for a day, then served from cache while the browser
# revalidates in the background for up to a week. Nothing waits on them, and
# a regenerated icon (scripts/gen-icons.py) still shows up within a day.
/icon*
  Cache-Control: public, max-age=86400, stale-while-revalidate=604800
/favicon-*
  Cache-Control: public, max-age=86400, stale-while-revalidate=604800
/apple-touch-icon.png
  Cache-Control: public, max-age=86400, stale-while-revalidate=604800
/og.png
  Cache-Control: public, max-age=86400, stale-while-revalidate=604800
/manifest.webmanifest
  Cache-Control: public, max-age=86400, stale-while-revalidate=604800

# Read by crawlers, not people; an hour is plenty.
/robots.txt
  Cache-Control: public, max-age=3600
/sitemap.xml
  Cache-Control: public, max-age=3600

# Deliberately NOT here, so they keep the platform default
# (public, max-age=0, must-revalidate):
#  - every HTML page: a deploy - and a changed legal document behind the
#    consent gate - must be visible on the next load;
#  - /sw.js: the browser's own update check must see a new worker;
#  - /_app/version.json: SvelteKit's version signal.
# src/lib/cache-headers.test.ts holds these rules.
