mirror of
https://github.com/filebrowser/filebrowser.git
synced 2026-01-23 02:35:10 +00:00
feat: gzip encoding for static js files
This commit is contained in:
parent
4711e7bcd5
commit
aa172b8bb5
4 changed files with 483 additions and 1 deletions
|
|
@ -126,7 +126,22 @@ func getStaticHandlers(store *storage.Storage, server *settings.Server, assetsFs
|
|||
}
|
||||
}
|
||||
|
||||
http.FileServer(http.FS(assetsFs)).ServeHTTP(w, r)
|
||||
if !strings.HasSuffix(r.URL.Path, ".js") {
|
||||
http.FileServer(http.FS(assetsFs)).ServeHTTP(w, r)
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
fileContents, err := fs.ReadFile(assetsFs, r.URL.Path+".gz")
|
||||
if err != nil {
|
||||
return http.StatusNotFound, err
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Encoding", "gzip")
|
||||
w.Header().Set("Content-Type", "application/javascript; charset=utf-8")
|
||||
|
||||
if _, err := w.Write(fileContents); err != nil {
|
||||
return http.StatusInternalServerError, err
|
||||
}
|
||||
|
||||
return 0, nil
|
||||
}, "/static/", store, server)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue