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

Make sure that PDFs proxied by NGINX do get cached in Cloudflare #589

Open
seanh opened this issue Sep 6, 2021 · 2 comments
Open

Make sure that PDFs proxied by NGINX do get cached in Cloudflare #589

seanh opened this issue Sep 6, 2021 · 2 comments

Comments

@seanh
Copy link
Contributor

seanh commented Sep 6, 2021

The NGINX /proxy/static/ URLs for proxying PDFs need to end in ".pdf" or Cloudflare won't cache them (regardless of caching headers). See: https://hypothes-is.slack.com/archives/C1MA4E9B9/p1630943273021700?thread_ts=1630925851.005100&cid=C1MA4E9B9

In practice we only use this endpoint for proxying PDFs so we can probably get away with it always ending in ".pdf"?

NGINX may also need to strip caching-related headers from the third-party response and add its own caching headers in order to get Cloudflare to cach the responses. It looks like NGINX already does this:

# Cache for one day, but allow serving from cache while revalidating for a week.
# https://web.dev/stale-while-revalidate/
proxy_hide_header "Cache-Control";
add_header "Cache-Control" "public, max-age=86400, stale-while-revalidate=604800";
See #31 and #76

@seanh seanh changed the title Make sure that PDFs cached by NGINX have URLs ending in ".pdf" Make sure that PDFs proxied by NGINX have URLs ending in ".pdf" Sep 22, 2021
@seanh seanh changed the title Make sure that PDFs proxied by NGINX have URLs ending in ".pdf" Make sure that PDFs proxied by NGINX do get cached in Cloudflare Sep 22, 2021
@seanh
Copy link
Contributor Author

seanh commented Sep 22, 2021

We could also create a Cloudflare page rule for the endpoint, then we wouldn't need to add/remove caching headers and the URLs wouldn't need to end in ".pdf".

Slack thread: https://hypothes-is.slack.com/archives/C1MA4E9B9/p1632303338068500

@marcospri
Copy link
Member

We could also create a Cloudflare page rule for the endpoint, then we wouldn't need to add/remove caching headers and the URLs wouldn't need to end in ".pdf".

Created rule today. Waiting a day or two to see results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants