grafana-dee / microcosm

Front end for Microcosm, a Go web server that serves the static files, templates and performs API calls.
GNU Affero General Public License v3.0
11 stars 3 forks source link

Static file caching #130

Closed pascalopitz closed 2 years ago

pascalopitz commented 2 years ago

This controls caching behavior via using the startup time as last-modified and subsequent validation of if-modified-since

pascalopitz commented 2 years ago

I assume that before the actual file meta data could be used as last-modified, whereas for embedded assets that's not happening? We can think of the startup time as the last time something gets modified though,

grafana-dee commented 2 years ago

This is elegant and a far simpler fix than the one I was thinking of :)

pascalopitz commented 2 years ago

Well, my first thought was "ETAG" but I think this works just as well

grafana-dee commented 2 years ago

Fixes #128

grafana-dee commented 2 years ago

Well my thought was:

  1. Generate SHA hashes of all files.
  2. Populate a map of file names to hashes.
  3. Allow templates to obtain the hash (new filename) from the map.
  4. Force super long "forever cache" HTTP heads.

Works because we never need to invalidate any cache even when files change as the changed files are new files and templates would always point at new files.

Also would allow the hashes to be accessed for subresource integrity.