buro9 / 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 1 year ago

pascalopitz commented 1 year ago

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

pascalopitz commented 1 year 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,

buro9 commented 1 year ago

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

pascalopitz commented 1 year ago

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

buro9 commented 1 year ago

Fixes #128

buro9 commented 1 year 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.