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

Add better default caching #608

Merged
merged 1 commit into from
Jan 3, 2020
Merged

Add better default caching #608

merged 1 commit into from
Jan 3, 2020

Conversation

tunetheweb
Copy link
Member

Closes #413

This sets the following cache control settings:

Note the static files need to be set in two different places depending whether they are served by Google App Engine (production) or Python/Flask (for local development) and I set in both for consistency. And I've not been able to test the App Engine changes so will need to double check it when deployed.

Background:

In #423 @paulcalvano noted the Google App engine default of 600 seconds (10 mins) for static content and no caching for dynamic content was too low but we didn't really agree what the higher limit should be.

Some advocate for extremely large times (e.g. 1 year) but this depends on immutable resources, which we don't currently have as we don't currently set a unique hash value in our static resource file names. The longer we make it, the more risk of showing broken content or not being in control to change it. I'm also sceptical as to the benefit of longer term caching to be honest: unless you are a very popular site visited frequently by the users, I'd imagine most users won't have your assets cached between sessions and caching is really for within a session when the user is browsing about the site so short term caching is actually fine in my opinion. However I agree 10 mins is too short - as some of our articles could easily take over 10 mins to read.

Therefore I've gone with a relatively small 3 hours for most resources. So if someone is browsing around the site then they should not have to reload caching - unless here for an extremely long time, in which case they might take a small hit every 3 hours! I could even be persuaded to move this to 1 hour. I'm also a fan of having a bit of caching for HTML since it shouldn't change much either and it makes browsing around the site a lot quicker.

This should also move us from the frankly embarrassing F we get in the caching when you run webpagetest on our site:

image

However will likely still give us a lower ranking (my own blog follows the same rules and gets a D rating). Saying that, it does set us up for how to set this in future if we do want to make longer caching, for example if we move to immutable static resources with unique filenames.

Thoughts on this strategy - and on the PR in general - greatly appreciated!

@tunetheweb tunetheweb added the development Building the Almanac tech stack label Dec 29, 2019
@tunetheweb tunetheweb self-assigned this Dec 29, 2019
src/main.py Show resolved Hide resolved
@tunetheweb tunetheweb merged commit 809e4e4 into master Jan 3, 2020
@tunetheweb tunetheweb deleted the cache_control branch January 3, 2020 07:25
This was referenced Jan 18, 2020
@tunetheweb tunetheweb mentioned this pull request Jan 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
development Building the Almanac tech stack
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Audit the website for performance issues
2 participants