-
-
Notifications
You must be signed in to change notification settings - Fork 676
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
Sensible cache-control
headers for static assets, including those served by plugins
#1645
Comments
I agree: this is bad. Ideally, content served from
Datasette half-implemented the first of these: if you view source on https://latest.datasette.io/ you'll see it links to
I had forgotten I had implemented this! Here is how it is calculated: Lines 510 to 516 in 458f03a
So
The larger question though is what to do about other assets. I'm particularly interested in plugin assets, since visualization plugins like |
The existing |
It sounds like you can workaround this with Varnish configuration for the moment, but I'm going to bump this up the list of things to fix - it's particularly relevant now as I'd like to get a solution in place before Datasette 1.0, since it's likely to be beneficial to plugins and hence should be part of the stable, documented plugin interface. |
Cache-control
header missing for static assetscache-control
headers for static assets, including those served by plugins
Hah, found a TODO about this: Lines 997 to 999 in c579115
|
What I'm seeing
With
default_cache_ttl = 86400
, I see the following:A table view returns
Cache-control: max-age=86400
:A static asset returns no
Cache-control
header:What I expected to see
I expected the static asset to return a
Cache-control
header indicating that this response can be cached.Why this matters
I'm productionising a Datasette deployment right now and was looking into putting it behind a Varnish instance. I was surprised to see requests for static assets being served from Datasette rather than Varnish, this is what led me to look more closely at the response headers.
While Datasette serves those static assets pretty quickly, I don't see why Datasette should serve them. By their nature, static assets like images and JS files are very cacheable, so it should be easy to serve them from a cache like Varnish.
(Note that Varnish can easily be configured to override this header, enabling caching for static assets. But it would be better if this override was not necessary.)
Discussion
It seems clear to me that serving static assets without a
Cache-control
header is not ideal.I see two options here:
A. Static assets use the same logic as table / SQL views to set the
Cache-control
header based ondefault_cache_ttl
.B. An additional setting for static assets is introduced (
default_static_cache_ttl
, say).The text was updated successfully, but these errors were encountered: