feat: add hashfs for static asset cache busting and live clock
- Add assets package with dev/prod build tags - Dev: serve from filesystem with Cache-Control: no-store - Prod: use hashfs for cache-busting URLs - Add LiveClock component to show SSE connection status - Update templates to use StaticPath for asset URLs
This commit is contained in:
26
assets/static_prod.go
Normal file
26
assets/static_prod.go
Normal file
@@ -0,0 +1,26 @@
|
||||
//go:build !dev
|
||||
|
||||
package assets
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"net/http"
|
||||
|
||||
"github.com/benbjohnson/hashfs"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
var (
|
||||
//go:embed css js
|
||||
staticFiles embed.FS
|
||||
staticSys = hashfs.NewFS(staticFiles)
|
||||
)
|
||||
|
||||
func Handler() http.Handler {
|
||||
log.Debug().Msg("static assets are embedded with hashfs")
|
||||
return hashfs.FileServer(staticSys)
|
||||
}
|
||||
|
||||
func StaticPath(path string) string {
|
||||
return "/" + staticSys.HashName(path)
|
||||
}
|
||||
Reference in New Issue
Block a user