Skip to content

High performance, self-hosted, newsletter and mailing list manager with a modern dashboard. Single binary app.

Add a `?v=hash` cache breaker (that changes on restart) to static assets.

Kailash Nadh0c9dc074791d
diff --git a/Makefile b/Makefile
index f6e388bb..2686438f 100644
--- a/Makefile
+++ b/Makefile
@@ -13,6 +13,7 @@ FRONTEND_YARN_MODULES = frontend/node_modules
FRONTEND_DIST = frontend/dist
FRONTEND_DEPS = \
$(FRONTEND_YARN_MODULES) \
+ frontend/index.html \
frontend/package.json \
frontend/vite.config.js \
frontend/.eslintrc.js \
diff --git a/cmd/handlers.go b/cmd/handlers.go
index af92a5a4..9cc4f88b 100644
--- a/cmd/handlers.go
+++ b/cmd/handlers.go
@@ -1,6 +1,7 @@
package main
import (
+ "bytes"
"crypto/subtle"
"net/http"
"path"
@@ -237,6 +238,8 @@ func handleAdminPage(c echo.Context) error {
return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
}
+ b = bytes.ReplaceAll(b, []byte("asset_version"), []byte(app.constants.AssetVersion))
+
return c.HTMLBlob(http.StatusOK, b)
}
diff --git a/cmd/init.go b/cmd/init.go
index 8905f113..56cb6c48 100644
--- a/cmd/init.go
+++ b/cmd/init.go
@@ -2,6 +2,7 @@ package main
import (
"bytes"
+ "crypto/md5"
"encoding/json"
"fmt"
"html/template"
@@ -94,6 +95,7 @@ type constants struct {
OptinURL string
MessageURL string
ArchiveURL string
+ AssetVersion string
MediaUpload struct {
Provider string
@@ -414,6 +416,9 @@ func initConstants() *constants {
c.BounceSendgridEnabled = ko.Bool("bounce.sendgrid_enabled")
c.BouncePostmarkEnabled = ko.Bool("bounce.postmark.enabled")
+ b := md5.Sum([]byte(time.Now().String()))
+ c.AssetVersion = fmt.Sprintf("%x", b)[0:10]
+
return &c
}
@@ -756,6 +761,7 @@ func initHTTPServer(app *App) *echo.Echo {
RootURL: app.constants.RootURL,
LogoURL: app.constants.LogoURL,
FaviconURL: app.constants.FaviconURL,
+ AssetVersion: app.constants.AssetVersion,
EnablePublicSubPage: app.constants.EnablePublicSubPage,
EnablePublicArchive: app.constants.EnablePublicArchive,
}
diff --git a/cmd/public.go b/cmd/public.go
index ff61637a..9ed9228b 100644
--- a/cmd/public.go
+++ b/cmd/public.go
@@ -30,6 +30,7 @@ type tplRenderer struct {
RootURL string
LogoURL string
FaviconURL string
+ AssetVersion string
EnablePublicSubPage bool
EnablePublicArchive bool
}
@@ -41,6 +42,7 @@ type tplData struct {
RootURL string
LogoURL string
FaviconURL string
+ AssetVersion string
EnablePublicSubPage bool
EnablePublicArchive bool
Data interface{}
@@ -94,6 +96,7 @@ func (t *tplRenderer) Render(w io.Writer, name string, data interface{}, c echo.
RootURL: t.RootURL,
LogoURL: t.LogoURL,
FaviconURL: t.FaviconURL,
+ AssetVersion: t.AssetVersion,
EnablePublicSubPage: t.EnablePublicSubPage,
EnablePublicArchive: t.EnablePublicArchive,
Data: data,
diff --git a/frontend/index.html b/frontend/index.html
index bcf87f48..07d91a7a 100644
--- a/frontend/index.html
+++ b/frontend/index.html
@@ -4,9 +4,9 @@
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
- <link rel="icon" href="/admin/static/favicon.png" />
- <link href="/admin/custom.css" rel="stylesheet" type="text/css">
- <script src="/admin/custom.js" async defer></script>
+ <link rel="icon" href="/admin/static/favicon.png?v=asset_version" />
+ <link href="/admin/custom.css?v=asset_version" rel="stylesheet" type="text/css">
+ <script src="/admin/custom.js?v=asset_version" async defer></script>
<title>listmonk</title>
</head>
<body>
diff --git a/static/public/templates/index.html b/static/public/templates/index.html
index 004ea079..057ab87f 100644
--- a/static/public/templates/index.html
+++ b/static/public/templates/index.html
@@ -12,14 +12,14 @@
href="{{ .RootURL }}/archive.xml" />
{{ end }}
- <link href="/public/static/style.css?v2.3.0" rel="stylesheet" type="text/css" />
- <link href="/public/custom.css" rel="stylesheet" type="text/css">
- <script src="/public/custom.js" async defer></script>
+ <link href="/public/static/style.css?v={{ .AssetVersion }}" rel="stylesheet" type="text/css" />
+ <link href="/public/custom.css?v={{ .AssetVersion }}" rel="stylesheet" type="text/css">
+ <script src="/public/custom.js?v={{ .AssetVersion }}" async defer></script>
{{ if ne .FaviconURL "" }}
<link rel="shortcut icon" href="{{ .FaviconURL }}" type="image/x-icon" />
{{ else }}
- <link rel="shortcut icon" href="/public/static/favicon.png" type="image/x-icon" />
+ <link rel="shortcut icon" href="/public/static/favicon.png?v={{ .AssetVersion }}" type="image/x-icon" />
{{ end }}
</head>
<body>
@@ -30,7 +30,7 @@
{{ if ne .LogoURL "" }}
<img src="{{ .LogoURL }}" alt="{{ .Data.Title }}" /></a>
{{ else }}
- <img src="/public/static/logo.svg" alt="{{ .Data.Title }}" />
+ <img src="/public/static/logo.svg?v={{ .AssetVersion }}" alt="{{ .Data.Title }}" />
{{ end }}
</a>
</div>