Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix README Handle path #4

Merged
merged 1 commit into from
Feb 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ 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`
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`. Note the hash is truncated for brevity. When
`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
Expand All @@ -29,7 +29,7 @@ var fsys = hashfs.NewFS(embedFS)
Then attach a `hashfs.FileServer()` to your router:

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

Next, your html templating library can obtain the hashname of your file using
Expand All @@ -38,7 +38,7 @@ the `hashfs.FS.HashName()` method:
```go
func renderHTML(w io.Writer) {
fmt.Fprintf(w, `<html>`)
fmt.Fprintf(w, `<script script="/assets/%s">`, fsys.HashName("scripts/main.js"))
fmt.Fprintf(w, `<script src="/assets/%s"></script>`, fsys.HashName("scripts/main.js"))
fmt.Fprintf(w, `</html>`)
}
```