Skip to content
Projets

benbjohnson/hashfs has 385 GitHub stars and 16 forks. GitHot measured 0 stars in 24 hours and 0 in 7 days. Last checked 2026-11-24 10:41 UTC. Last push 2024-02-22.

Comment ces chiffres sont mesurés

Progression mesurée des étoiles

in 24h
0
in 7 days
0
in 15 days
Historique en cours
in 1 month
Historique en cours

Variations nettes sur des périodes qui se chevauchent, pas des totaux quotidiens. Les mesures absentes restent vides. Les étoiles indiquent l’intérêt, pas la qualité.

À propos

Implementation of io/fs.FS that appends SHA256 hashes to filenames to allow for aggressive HTTP caching.

Outils de développement

README.md

Original

hashfs

Implementation of io/fs.FS that appends SHA256 hashes to filenames to allow for aggressive HTTP caching.

For example, given a file path of scripts/main.js, the hashfs.FS filesystem will provide the server with a hashname of scripts/main-b633a..d628.js (the hash is truncated for brevity in the example). When this file path is requested by the client, the server can verify the hash and return the contents with an aggressive Cache-Control header. The client will cache this file for up to a year and does not need to re-request it in the future.

Note that this library requires Go 1.16 or higher.

Usage

To use hashfs, first wrap your embed.FS in a hashfs.FS filesystem:

//go:embed scripts stylesheets images
var embedFS embed.FS

var fsys = hashfs.NewFS(embedFS)

Then attach a hashfs.FileServer() to your router:

http.Handle("/assets/", http.StripPrefix("/assets/", hashfs.FileServer(fsys)))

Next, your html templating library can obtain the hashname of your file using the hashfs.FS.HashName() method:

func renderHTML(w io.Writer) {
	fmt.Fprintf(w, `<html>`)
	fmt.Fprintf(w, `<script src="/assets/%s"></script>`, fsys.HashName("scripts/main.js"))
	fmt.Fprintf(w, `</html>`)
}

Explorer des projets similaires

Chargement…