about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAlan Pearce2024-05-15 09:53:51 +0200
committerAlan Pearce2024-05-15 09:53:51 +0200
commit91836fef16532b72d9fd3edbcbe3844d9c541345 (patch)
treee1a7e56127373b33d97b2d23fd5b6ae620fb42b5
parent1a5c82e2d08accb6330c4164ab987b87157b10ed (diff)
downloadsearchix-91836fef16532b72d9fd3edbcbe3844d9c541345.tar.lz
searchix-91836fef16532b72d9fd3edbcbe3844d9c541345.tar.zst
searchix-91836fef16532b72d9fd3edbcbe3844d9c541345.zip
perf: move scripts to head to enable fetching in parallel
-rw-r--r--frontend/templates/index.gotmpl6
-rw-r--r--internal/config/config.go2
-rw-r--r--internal/server/mux.go10
3 files changed, 9 insertions, 9 deletions
diff --git a/frontend/templates/index.gotmpl b/frontend/templates/index.gotmpl
index 8bff09c..6db4cc2 100644
--- a/frontend/templates/index.gotmpl
+++ b/frontend/templates/index.gotmpl
@@ -6,6 +6,9 @@
     <title>Searchix</title>
     <link href="/static/base.css" rel="stylesheet" />
     <link href="/static/style.css" rel="stylesheet" />
+    {{ block "js" . }}
+    {{ end }}
+    {{ .ExtraHeadHTML }}
   </head>
   <body>
     <header>
@@ -33,8 +36,5 @@
       Made by <a href="https://alanpearce.eu">Alan Pearce</a>.
       <a href="https://todo.sr.ht/~alanpearce/searchix">Report issues</a>
     </footer>
-    {{ block "js" . }}
-    {{ end }}
-    {{ .ExtraBodyHTML }}
   </body>
 </html>
diff --git a/internal/config/config.go b/internal/config/config.go
index add4e67..3cf8c5c 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -70,7 +70,7 @@ type Web struct {
 	BaseURL               URL
 	SentryDSN             string
 	Environment           string
-	ExtraBodyHTML         template.HTML
+	ExtraHeadHTML         template.HTML
 	Headers               map[string]string
 }
 
diff --git a/internal/server/mux.go b/internal/server/mux.go
index 0f32507..f37bd6e 100644
--- a/internal/server/mux.go
+++ b/internal/server/mux.go
@@ -46,7 +46,7 @@ type TemplateData struct {
 	Query         string
 	Results       bool
 	SourceResult  *bleve.SearchResult
-	ExtraBodyHTML template.HTML
+	ExtraHeadHTML template.HTML
 	Version       VersionInfo
 }
 
@@ -102,7 +102,7 @@ func NewMux(
 	mux := http.NewServeMux()
 	mux.HandleFunc("/{$}", func(w http.ResponseWriter, _ *http.Request) {
 		indexData := TemplateData{
-			ExtraBodyHTML: config.Web.ExtraBodyHTML,
+			ExtraHeadHTML: config.Web.ExtraHeadHTML,
 			Sources:       config.Importer.Sources,
 			Version:       *versionInfo,
 		}
@@ -149,7 +149,7 @@ func NewMux(
 
 			tdata := ResultData[options.NixOption]{
 				TemplateData: TemplateData{
-					ExtraBodyHTML: config.Web.ExtraBodyHTML,
+					ExtraHeadHTML: config.Web.ExtraHeadHTML,
 					Source:        *source,
 					Sources:       config.Importer.Sources,
 					Version:       *versionInfo,
@@ -209,7 +209,7 @@ func NewMux(
 			}
 
 			err = templates["search"].Execute(w, TemplateData{
-				ExtraBodyHTML: config.Web.ExtraBodyHTML,
+				ExtraHeadHTML: config.Web.ExtraHeadHTML,
 				Sources:       config.Importer.Sources,
 				Source:        *source,
 				SourceResult:  sourceResult,
@@ -227,7 +227,7 @@ func NewMux(
 
 	if liveReload {
 		applyDevModeOverrides(config)
-		config.Web.ExtraBodyHTML = jsSnippet
+		config.Web.ExtraHeadHTML = jsSnippet
 		liveReload := livereload.New()
 		liveReload.Start()
 		top.Handle("/livereload", liveReload)