[PR #2349] [MERGED] fix: allow browser caching for file downloads #9920

Closed
opened 2026-04-23 09:17:22 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/go-vikunja/vikunja/pull/2349
Author: @maggch97
Created: 3/3/2026
Status: Merged
Merged: 3/4/2026
Merged by: @kolaente

Base: mainHead: fix/file-download-caching


📝 Commits (1)

  • 1215da0 fix: allow browser caching for file downloads (backgrounds, attachments)

📊 Changes

2 files changed (+24 additions, -1 deletions)

View changed files

📝 pkg/modules/background/handler/background.go (+13 -1)
📝 pkg/routes/api/v1/task_attachment.go (+11 -0)

📄 Description

Problem

The global API middleware sets Cache-Control: no-store on all /api/v1/ responses to prevent browsers from heuristically caching JSON data. However, this also applies to binary file downloads (project backgrounds, task attachments), causing browsers to re-download these files on every request — even though they have Last-Modified headers set.

Fix

Override Cache-Control to no-cache in the file download endpoints for:

  • Project backgrounds (/api/v1/projects/{id}/background)
  • Task attachments (/api/v1/tasks/{id}/attachments/{id})

no-cache allows the browser to store the file locally but requires revalidation via If-Modified-Since before using the cached copy. Since these files are immutable (updates create a new file with a new ID), the Last-Modified header already set by these endpoints is sufficient for correct revalidation.

Export downloads are intentionally left with no-store since they are one-time downloads.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/go-vikunja/vikunja/pull/2349 **Author:** [@maggch97](https://github.com/maggch97) **Created:** 3/3/2026 **Status:** ✅ Merged **Merged:** 3/4/2026 **Merged by:** [@kolaente](https://github.com/kolaente) **Base:** `main` ← **Head:** `fix/file-download-caching` --- ### 📝 Commits (1) - [`1215da0`](https://github.com/go-vikunja/vikunja/commit/1215da004c0346b2afa90d0656ffa01ecd4de7cb) fix: allow browser caching for file downloads (backgrounds, attachments) ### 📊 Changes **2 files changed** (+24 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `pkg/modules/background/handler/background.go` (+13 -1) 📝 `pkg/routes/api/v1/task_attachment.go` (+11 -0) </details> ### 📄 Description ## Problem The global API middleware sets `Cache-Control: no-store` on all `/api/v1/` responses to prevent browsers from heuristically caching JSON data. However, this also applies to binary file downloads (project backgrounds, task attachments), causing browsers to re-download these files on every request — even though they have `Last-Modified` headers set. ## Fix Override `Cache-Control` to `no-cache` in the file download endpoints for: - **Project backgrounds** (`/api/v1/projects/{id}/background`) - **Task attachments** (`/api/v1/tasks/{id}/attachments/{id}`) `no-cache` allows the browser to store the file locally but requires revalidation via `If-Modified-Since` before using the cached copy. Since these files are immutable (updates create a new file with a new ID), the `Last-Modified` header already set by these endpoints is sufficient for correct revalidation. Export downloads are intentionally left with `no-store` since they are one-time downloads. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-23 09:17:22 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/vikunja#9920