Skip to content

Cloudflare Workers (Beta Assets). Broken Caching _headers #13164

@predaytor

Description

@predaytor

Astro Info

Astro                    v4.15.11
Node                     v22.8.0
System                   macOS (arm64)
Package Manager          npm
Output                   server
Adapter                  @astrojs/cloudflare
Integrations             astro-robots-txts

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

Using the experimental deployment of Cloudflare Workers for Astro, caching does not seem to work for paths specified in _headers.

Response headers for static assets: cache-control: public, max-age=0, must-revalidate.

https://my-astro-app.thepredaytor.workers.dev/

public/_routes.json:

{
  "version": 1,
  "include": [
    "/*"
  ],
  "exclude": [
    "/_astro/*",
    "/.assetsignore",
    "/favicon.svg"
  ]
}

public/_headers:

/_astro/*
  Cache-Control: public, max-age=31557600, immutable

/favicon.ico
  Cache-Control: public, max-age=3600, immutable

/favicon.svg
  Cache-Control: public, max-age=3600, immutable

wrangler.toml:

#:schema node_modules/wrangler/config-schema.json
name = "my-astro-app"
compatibility_date = "2024-10-04"
compatibility_flags = ["nodejs_compat_v2"]
main = "./dist/_worker.js"
assets = { directory = "./dist", binding = "ASSETS" }

# Workers Logs
# Docs: https://developers.cloudflare.com/workers/observability/logs/workers-logs/
# Configuration: https://developers.cloudflare.com/workers/observability/logs/workers-logs/#enable-workers-logs
[observability]
enabled = true

[vars]
MY_VARIABLE = "test"

What's the expected result?

The response headers must represent those defined in the _headers file.

Link to Minimal Reproducible Example

https://stackblitz.com/github/predaytor/astro-cloudflare

Participation

  • I am willing to submit a pull request for this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    - P2: has workaroundAn edge case that only affects very specific usage, but has a trivial workaround (priority)pkg: cloudflareRelated to the Cloudflare adapterwontfixThe Astro maintainers won't be fixing this issue, however community PRs are still welcome.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions