Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 task done
predaytor opened this issue Oct 6, 2024 · 2 comments
Open
1 task done

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

predaytor opened this issue Oct 6, 2024 · 2 comments
Labels
- P2: has workaround Bug, but has workaround (priority) upstream wontfix This will not be worked on

Comments

@predaytor
Copy link

predaytor commented Oct 6, 2024

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.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Oct 6, 2024
@florian-lefebvre florian-lefebvre transferred this issue from withastro/astro Oct 7, 2024
@alexanderniebuhr
Copy link
Member

@predaytor I need to confirm with the Cloudflare Team first, before I can give you an answer, but I'm not sure if Worker Assets support the _headers file in the same level as Pages do.

@petebacondarwin
Copy link

Yes, currently Workers + Assets does not read any of _headers, _redirects nor _routes.json.
The basic configuration of Workers + Assets appears to avoid the need for _routes.json in almost every case so far.

We are deciding what to do about the other two. Both can be handled in different ways with Workers.

For example it should be possible to setup Cloudflare Snippets in front of a Workers + Assets worker that can do things like redirects and modifying headers based on requests.

@alexanderniebuhr alexanderniebuhr added wontfix This will not be worked on upstream - P2: has workaround Bug, but has workaround (priority) and removed needs triage Issue needs to be triaged labels Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P2: has workaround Bug, but has workaround (priority) upstream wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants