Skip to content
cache-control middleware
CSS Go
Branch: master
Clone or download
Latest commit 01b38e1 Jan 2, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
assets using same underlying http.FileSystem Sep 21, 2017
.gitignore notes Jan 1, 2018
LICENSE Initial commit Sep 19, 2017
README.md notes Jan 1, 2018
cache-control.go show errors in dev mode Jan 2, 2018
cache-control_test.go using same underlying http.FileSystem Sep 21, 2017

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

  • dirwatch can be used for watching directories of assets (next).
  • more tests
You can’t perform that action at this time.