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

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

Merged
merged 2 commits into from
Jan 20, 2025

Conversation

ankush
Copy link
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
2 of 4 checks passed
@ankush ankush deleted the http_headers branch January 20, 2025 10:02
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