cache-control middleware adds ETag header (md5 of the content) and Cache-Control header
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)
})
- dirwatch can be used for watching directories of assets (next).
- more tests