Enable HTTP caching (adds Cache-Control and Vary headers, changes some APIs from POST to GET, replaces time= with tz=)#320
Open
da2x wants to merge 9 commits into
Open
Enable HTTP caching (adds Cache-Control and Vary headers, changes some APIs from POST to GET, replaces time= with tz=)#320da2x wants to merge 9 commits into
da2x wants to merge 9 commits into
Conversation
Static JavaScript assets (unless the admin changes settings) get 0:30–24:00 hour freshness with async revalidating. The related API responses get 2–58 second freshness, with caches retaining stale data for up to 5 min on server errors.
HTTP request headers that influence the response needs to go in the Vary response header.
Replaces time request argument containing the client's current time with tz containing their time zone offset. Better for caching. Properly handles time zone-adjusting dates and time. Times are no longer off by up to a minute.
Contributor
Author
|
I’m done with this now. The main comment loading is still not cachable. I’ll handle that in a separate package after this is merged. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
timerequest argument withtzand proper time zone handling (less request variability, one variant per time zone instead of one per minute of the day). Also adjusts dates as well as times to the user’s time zone.This only enabled caching on some assets, and not any responses that change per-user or based on cookies. It means admins may be confused by their sites not immediately changing when they change a setting that modifies these assets. I decided to focus on the end user and their experience instead. You should’t need to change settings all that often, so this is a much smaller use case anyway. A compromise could be to disable caching for the admins, but this wouldn’t be a true representation of how users experience their sites. (Admins using HashOver are therefor expected to understand caching and how to turn it off in developer tools.)
I thought long and hard about where to put the caching headers. I decided they belonged where they’re used. I figured confused developers would look at the code to figure out why a changed setting didn’t apply as expected. Greeting them with the cache header should explain it, so it’s better for code readability. I can make it a function inside
Setupinstead if you hate this.Bonus sneaking in along with the others:
Sec-CH-UA-Mobileclient hint instead ofUser-Agentto determine device mobileness (when available; e.g. Edge and Chrome over HTTPS). This is part of the client hints standard and is meant to replace User-Agents in the future. Among other things, it’s better for caching (varying on one boolean vs the entire User-Agent string).Each change is its own commit, so you can merge just the parts you want.