Fix h2 push

This commit is contained in:
Ken-Håvard Lieng 2019-01-25 02:32:22 +01:00
parent 815b518c2c
commit aab1ad3e99
4 changed files with 55 additions and 56 deletions

View file

@ -2,7 +2,7 @@ package server
type indexTemplateData struct {
InlineScript string
CSSPath string
Stylesheet string
Scripts []string
}
@ -13,16 +13,20 @@ const indexTemplate = `
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#f0f0f0">
<meta name="theme-color" content="#222">
<title>Dispatch</title>
<meta name="description" content="Web-based IRC client.">
<link rel="preload" href="/init" as="fetch" crossorigin>
{{if .InlineScript}}
{{if .InlineScript}}
<script>{{.InlineScript}}</script>
{{end}}
{{end}}
{{range .Scripts}}
<script src="{{.}}" defer></script>
{{end}}
<link rel="preload" href="/font/fontello.woff2?48901973" as="font" type="font/woff2" crossorigin>
<link rel="preload" href="/font/RobotoMono-Regular.woff2" as="font" type="font/woff2" crossorigin>
@ -30,21 +34,16 @@ const indexTemplate = `
<link rel="preload" href="/font/Montserrat-Bold.woff2" as="font" type="font/woff2" crossorigin>
<link rel="preload" href="/font/RobotoMono-Bold.woff2" as="font" type="font/woff2" crossorigin>
{{if .CSSPath}}
<link href="/{{.CSSPath}}" rel="stylesheet">
{{if .Stylesheet}}
<link href="{{.Stylesheet}}" rel="stylesheet">
{{end}}
<link rel="manifest" href="/manifest.json">
</head>
<body>
<div id="root"></div>
{{range .Scripts}}
<script src="/{{.}}"></script>
{{end}}
<noscript>This page needs JavaScript enabled to function.</noscript>
<div id="root"></div>
</body>
</html>`

View file

@ -93,10 +93,10 @@ func (d *Dispatch) initFileServer() {
hash.Write(runtime)
inlineScriptSha256 = base64.StdEncoding.EncodeToString(hash.Sum(nil))
indexStylesheet := findAssetName("main*.css")
indexStylesheet := "/" + findAssetName("main*.css")
indexScripts := []string{
findAssetName("vendors*.js"),
findAssetName("main*.js"),
"/" + findAssetName("vendors*.js"),
"/" + findAssetName("main*.js"),
}
h2PushAssets = []h2PushAsset{
@ -145,7 +145,7 @@ func (d *Dispatch) initFileServer() {
}
renderIndexPage(indexTemplateData{
CSSPath: indexStylesheet,
Stylesheet: indexStylesheet,
InlineScript: inlineScript,
Scripts: indexScripts,
})