Skip to content

Allow browser caching for notebook book PDF#1219

Draft
terryyin wants to merge 1 commit intomainfrom
cursor/browser-pdf-caching-269f
Draft

Allow browser caching for notebook book PDF#1219
terryyin wants to merge 1 commit intomainfrom
cursor/browser-pdf-caching-269f

Conversation

@terryyin
Copy link
Copy Markdown
Member

@terryyin terryyin commented Apr 8, 2026

Summary

The book reader loads the PDF via GET /api/notebooks/{id}/book/file. That response did not advertise cacheability and used Content-Disposition: attachment, which is oriented toward downloads rather than in-app viewing.

Changes

  • Cache-Control: private, long max-age (365 days), must-revalidate so the client can reuse the response while still revalidating when appropriate.
  • ETag: Derived from the stable storage ref (source_file_ref), so it changes when the underlying blob changes without hashing the full PDF on every request.
  • If-None-Match: Returns 304 Not Modified when the client sends a matching ETag.
  • Content-Disposition: Switched from attachment to inline so browsers treat the resource as viewable in-page (the app still uses fetch + pdf.js; filename is preserved for save-as if needed).

Tests

  • Extended NotebookBooksControllerTest for cache headers, ETag, and 304 behavior.

Slack Thread

Open in Web Open in Cursor 

- Send Cache-Control private max-age for GET .../book/file
- ETag from stable source_file_ref so revalidation avoids full body
- Content-Disposition inline for in-browser viewing (fetch still works)
- Return 304 when If-None-Match matches

Co-authored-by: Terry Yin <terry.yinzhe@gmail.com>
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

Successfully merging this pull request may close these issues.

2 participants