Skip to content

send_file should set conditional=True and no-cache by default #1882

Description

@davidism

Currently, send_file sets cache_timeout to 12 hours, and disables conditional by default. We see a regular stream of questions from developers who are confused why their CSS changes aren't reflected in development, or even when deploying a new version. 12 hours is really long, even CDNs default to around 1-4 hours.

Instead, we should set conditional=True by default, set cache_control.no_cache instead of public, and not set max_age or expires. This will tell the client to cache the response, but to make conditional requests to decide whether to use the cache.

This will solve the issue developers are having with stale resources. It adds a bit of overhead since it requires a request cycle to calculate if the conditions are still met, but I think this should be negligible for most applications. If an application is at the point where that overhead matters, they should be using a CDN, at which point they would be tuning cache-control anyway.

Related to #1850

cc @jab

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions