I have action to send static files
func (ws *webserver) staticAction(w http.ResponseWriter, r *http.Request) bool {
staticFile, err := filepath.Abs(path.Join(ws.staticPath, path.Clean(r.URL.Path)))
if err == nil {
fi, err := os.Stat(staticFile)
if err == nil {
if mode := fi.Mode(); mode.IsRegular() {
http.ServeFile(w, r, staticFile)
return true
}
}
}
return false
}
There is a need to compress statics css and js.
http.ServeFile suppor range bytes, and if compress the return from http.ServeFile the file structure will be broken.
I do not see any other way out how to abandon range bytes, for example, by removing headers between the client and the server reporting range support or need write own solution
It is assumed that the front server like nginx will not install
2
Answers
I had to write my own stub, which will disable the header range and encode the files Maybe someone will be useful
This library https://github.com/vearutop/statigz (I’m the author) can serve pre-compressed assets using
embed
package of go1.16+, file ranges are supported with no additional configuration.