PlaidWeb / Publ

Flexible publishing system for the web
http://publ.beesbuzz.biz/
MIT License
40 stars 4 forks source link

Allow setting cache-control headers on particular templates #525

Closed fluffy-critter closed 1 year ago

fluffy-critter commented 1 year ago

Expected Behavior

Right now, even though Publ correctly sets ETag headers to avoid needing to redownload things, there's no cache-control headers, so the browser still has to do the whole If-None-Match flow. Unfortunately this often leads to a Flash of Unstyled Content (FOUC) especially when stylesheets get a bit more complex or nested.

Once upon a time, Publ would set cache-control headers on responses to match the cache timeout values. This should probably be brought back.

Possible Solution

Ideally, the cache-control header should not be set for requests that access the user property, since that can lead to unexpected caching behavior when people log in or out.

So, for requests that access user (either from checking the user object or checking e.g. entry authentication), the response header should be

Cache-Control: no-cache

and for templates that do not, it should be

Cache-Control: max-age=(cache timeout), must-revalidate

Access to the user object can be tracked in the flask.g stash.

Steps to Reproduce (for bugs)

1. 2. 3. 4.

Context