Skip to content

perf: Add aggresive cache-control headers for files and assets#157

Merged
ankush merged 2 commits intomasterfrom
http_headers
Jan 20, 2025
Merged

perf: Add aggresive cache-control headers for files and assets#157
ankush merged 2 commits intomasterfrom
http_headers

Conversation

@ankush
Copy link
Copy Markdown
Member

@ankush ankush commented Jan 17, 2025

  1. Make /assets cache immutable, they have hashes anyway.
  2. Add cache headers to typically cacheable files like images and media /files/* (copied the list from press)
  3. Private files via framework: perf: add cache-control headers on private files frappe#29221

In the worst case, ctrl+shift+r fixes any kind of stale cache anyway because they send no-cache header to the server. /files/* also have etag so even after invalidation it will just be refreshed using the etag.

The numbers are still not that aggressive but they are better than 0, we can increase over time if we don't see any issue.

Avoid ocassional request to validate, if hash matches then there's no
need to ever validate the URLs.

ref: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control
We have no cache headers at all on public files, so except browsers
trying to heuristically cache things, they don't end up getting cached.
@ankush ankush marked this pull request as ready for review January 17, 2025 12:28
@ankush ankush marked this pull request as draft January 17, 2025 12:29
ankush added a commit to ankush/frappe that referenced this pull request Jan 17, 2025
- Client(browser) side cache
- 1 hr expiry
- 1 day revalidation
- etagged by nginx in default config (so no data transfer on expiry still)

In conjunction with frappe/agent#157
ankush added a commit to frappe/frappe that referenced this pull request Jan 17, 2025
* perf: add cache-control headers on private files

- Client(browser) side cache
- 1 hr expiry
- 1 day revalidation
- etagged by nginx in default config (so no data transfer on expiry still)

In conjunction with frappe/agent#157

* fix: Don't override existing headers
@ankush ankush marked this pull request as ready for review January 17, 2025 17:10
mergify Bot pushed a commit to frappe/frappe that referenced this pull request Jan 20, 2025
* perf: add cache-control headers on private files

- Client(browser) side cache
- 1 hr expiry
- 1 day revalidation
- etagged by nginx in default config (so no data transfer on expiry still)

In conjunction with frappe/agent#157

* fix: Don't override existing headers

(cherry picked from commit 320798d)

# Conflicts:
#	frappe/app.py
mergify Bot pushed a commit to frappe/frappe that referenced this pull request Jan 20, 2025
* perf: add cache-control headers on private files

- Client(browser) side cache
- 1 hr expiry
- 1 day revalidation
- etagged by nginx in default config (so no data transfer on expiry still)

In conjunction with frappe/agent#157

* fix: Don't override existing headers

(cherry picked from commit 320798d)

# Conflicts:
#	frappe/app.py
@ankush ankush merged commit 47338d1 into master Jan 20, 2025
@ankush ankush deleted the http_headers branch January 20, 2025 10:02
ankush added a commit to frappe/frappe that referenced this pull request May 2, 2025
…29860)

* perf: add cache-control headers on private files (#29221)

* perf: add cache-control headers on private files

- Client(browser) side cache
- 1 hr expiry
- 1 day revalidation
- etagged by nginx in default config (so no data transfer on expiry still)

In conjunction with frappe/agent#157

* fix: Don't override existing headers

(cherry picked from commit 320798d)

# Conflicts:
#	frappe/app.py

* chore: conflicts

---------

Co-authored-by: Ankush Menat <ankush@frappe.io>
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.

1 participant