cache-control middleware
CSS Go
Switch branches/tags
Nothing to show

README.md

cache-control

cache-control middleware adds ETag header (md5 of the content) and Cache-Control header

sample usage

Using chi router, we register this middleware before a http.FileServer:

fs := http.Dir(`./assets`)
assetServer := http.FileServer(fs)
rt.Route("/assets/*", func(rt chi.Router) {
	rt.Use(cachecontrol.CacheControl(
		fs,
		cachecontrol.StripPrefix("/assets")))
	rt.Get(
		"/*",
		http.StripPrefix("/assets", assetServer).ServeHTTP)
})

TODO

  • etag recauculation strategy: currently there is a dev mode, and in production etag won't get recalculated unless max-age passed (monitoring? using last-modified provided internally?)
  • more tests