Add Cloudflare Pages cache headers for static assets

Cloudflare Pages currently serves all responses with the default
'Cache-Control: public, max-age=0, must-revalidate', including
content-hashed files under /assets/* produced by the Docusaurus
build. Add a static/_headers file so Cloudflare Pages applies
long-lived immutable caching to /assets/* (safe because the filename
changes whenever the content changes) and a conservative one-day
max-age to /img/* and /images/*, which keep stable filenames and can
be replaced in place.

Also exclude _headers from the aws s3 sync step in the publish
workflow, since it is only meaningful for the Cloudflare deployment
and would otherwise be uploaded to S3/CloudFront and become publicly
accessible at /_headers there.
This commit is contained in:
Lunny Xiao
2026-07-25 15:14:23 -07:00
parent 45724f19ac
commit ae7956cc42
2 changed files with 18 additions and 1 deletions

View File

@@ -39,7 +39,7 @@ jobs:
aws-region: ${{ secrets.AWS_REGION}}
- name: Copy files to the production website with the AWS CLI
run: |
aws s3 sync build/ s3://docs-gitea-com
aws s3 sync build/ s3://docs-gitea-com --exclude "_headers"
aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_DISTRIBUTION}} --paths '/*'
- name: Copy files to Cloudflare Pages
env: