diff --git a/http-watcher.go b/http-watcher.go index b44ee5a..0f44bcb 100644 --- a/http-watcher.go +++ b/http-watcher.go @@ -234,12 +234,14 @@ func fileHandler(w http.ResponseWriter, path string, req *http.Request) { } w.Header().Set("Content-Type", ctype) } - if fi, err := os.Stat(path); err == nil { - w.Header().Set("Content-Length", fmt.Sprintf("%d", fi.Size())) + // text/html has larger size after appendReloadHook + if strings.HasPrefix(ctype, "text/html") { + w.WriteHeader(200) + io.Copy(w, f) + appendReloadHook(w, ctype, req) + return } - w.WriteHeader(200) - io.Copy(w, f) - appendReloadHook(w, ctype, req) + http.ServeFile(w, req, path) } }