benbjohnson / hashfs

Implementation of io/fs.FS that appends SHA256 hashes to filenames to allow for aggressive HTTP caching.
MIT License
353 stars 13 forks source link

MIME type #7

Open delaneyj opened 2 months ago

delaneyj commented 2 months ago

If I use the static path directly

<link rel="stylesheet" type="text/css" href="/static/css/site.css"/>

it works however if I generated the hashFS with a helper

<link rel="stylesheet" type="text/css" href={ staticPath("css/site.css") }/>
Refused to apply style from 'http://localhost:8080/servers/static/css/site-1630dff5128f31e61ad0a0b14c00d7e23df50237793a9c09d96bf564a8d54883.css' because its MIME type ('text/plain') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

Both way use the hashfs.FileServer so I'm surprised by the behavior. Any thoughts would helpful.

adoublef commented 1 month ago

is the staticPath function appending the static prefix after if locates the name using HashName? I had to do a bit of trickery when I just had an issue today:

func funcMap() template.FuncMap {
    return template.FuncMap{
        "static": func(s string) string {
            s = strings.TrimPrefix(s, "/static/")
            return "/static/" + static.HashName(s)
        },
    }
}