| 693 | } |
| 694 | |
| 695 | func (s *Handler) ServeInternalJS(w http.ResponseWriter, r *http.Request, name string) { |
| 696 | data, err := efs.ReadFile("internal/" + name + ".js") |
| 697 | if err != nil { |
| 698 | http.Error(w, "Internal Server Error", 500) |
| 699 | return |
| 700 | } |
| 701 | xx := xxhash.New() |
| 702 | xx.Write(data) |
| 703 | etag := fmt.Sprintf("w/\"%x\"", xx.Sum(nil)) |
| 704 | if r.Header.Get("If-None-Match") == etag { |
| 705 | w.WriteHeader(http.StatusNotModified) |
| 706 | return |
| 707 | } |
| 708 | header := w.Header() |
| 709 | header.Set("Content-Type", "application/javascript; charset=utf-8") |
| 710 | header.Set("Cache-Control", "public, max-age=0, must-revalidate") |
| 711 | header.Set("Etag", etag) |
| 712 | w.Write(data) |
| 713 | } |
| 714 | |
| 715 | func (s *Handler) ServeHmrWS(w http.ResponseWriter, r *http.Request) { |
| 716 | if r.Header.Get("Upgrade") != "websocket" { |