package host import ( "bytes" "strings" ) // ReloadScript is the JavaScript code injected into HTML pages for hot reload. const ReloadScript = `` // InjectReloadScript injects the live reload script into HTML content. // The script is inserted just before the closing tag. func InjectReloadScript(html []byte) []byte { // Try to inject before bodyEnd := bytes.LastIndex(html, []byte("")) if bodyEnd != -1 { result := make([]byte, 0, len(html)+len(ReloadScript)) result = append(result, html[:bodyEnd]...) result = append(result, []byte(ReloadScript)...) result = append(result, html[bodyEnd:]...) return result } // Try to inject before htmlEnd := bytes.LastIndex(html, []byte("")) if htmlEnd != -1 { result := make([]byte, 0, len(html)+len(ReloadScript)) result = append(result, html[:htmlEnd]...) result = append(result, []byte(ReloadScript)...) result = append(result, html[htmlEnd:]...) return result } // Append at the end as fallback result := make([]byte, 0, len(html)+len(ReloadScript)) result = append(result, html...) result = append(result, []byte(ReloadScript)...) return result } // IsHTMLContent checks if the content type indicates HTML. func IsHTMLContent(contentType string) bool { return strings.Contains(contentType, "text/html") }