{"id":13722405,"url":"https://github.com/benbjohnson/hashfs","last_synced_at":"2025-04-04T22:05:47.764Z","repository":{"id":45314369,"uuid":"320656043","full_name":"benbjohnson/hashfs","owner":"benbjohnson","description":"Implementation of io/fs.FS that appends SHA256 hashes to filenames to allow for aggressive HTTP caching.","archived":false,"fork":false,"pushed_at":"2024-02-22T20:48:57.000Z","size":19,"stargazers_count":370,"open_issues_count":2,"forks_count":12,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-02T21:05:49.153Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/benbjohnson.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-12-11T18:42:56.000Z","updated_at":"2025-03-31T05:16:02.000Z","dependencies_parsed_at":"2024-02-22T21:41:31.168Z","dependency_job_id":null,"html_url":"https://github.com/benbjohnson/hashfs","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benbjohnson%2Fhashfs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benbjohnson%2Fhashfs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benbjohnson%2Fhashfs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benbjohnson%2Fhashfs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/benbjohnson","download_url":"https://codeload.github.com/benbjohnson/hashfs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247256110,"owners_count":20909240,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T01:01:28.368Z","updated_at":"2025-04-04T22:05:47.742Z","avatar_url":"https://github.com/benbjohnson.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"hashfs\n======\n\nImplementation of io/fs.FS that appends SHA256 hashes to filenames to allow for\naggressive HTTP caching.\n\nFor example, given a file path of `scripts/main.js`, the `hashfs.FS`\nfilesystem will provide the server with a hashname of\n`scripts/main-b633a..d628.js` (the hash is truncated for brevity in the example). When\nthis file path is requested by the client, the server can verify the hash and\nreturn the contents with an aggressive `Cache-Control` header. The client will\ncache this file for up to a year and does not need to re-request it in the\nfuture.\n\nNote that this library requires Go 1.16 or higher.\n\n\n## Usage\n\nTo use `hashfs`, first wrap your `embed.FS` in a `hashfs.FS` filesystem:\n\n```go\n//go:embed scripts stylesheets images\nvar embedFS embed.FS\n\nvar fsys = hashfs.NewFS(embedFS)\n```\n\nThen attach a `hashfs.FileServer()` to your router:\n\n```go\nhttp.Handle(\"/assets/\", http.StripPrefix(\"/assets/\", hashfs.FileServer(fsys)))\n```\n\nNext, your html templating library can obtain the hashname of your file using\nthe `hashfs.FS.HashName()` method:\n\n```go\nfunc renderHTML(w io.Writer) {\n\tfmt.Fprintf(w, `\u003chtml\u003e`)\n\tfmt.Fprintf(w, `\u003cscript src=\"/assets/%s\"\u003e\u003c/script\u003e`, fsys.HashName(\"scripts/main.js\"))\n\tfmt.Fprintf(w, `\u003c/html\u003e`)\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenbjohnson%2Fhashfs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbenbjohnson%2Fhashfs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenbjohnson%2Fhashfs/lists"}