mirror of
https://github.com/knadh/listmonk.git
synced 2024-12-27 09:22:23 +08:00
Add a ?v=hash
cache breaker (that changes on restart) to static assets.
This commit is contained in:
parent
a2629c2c31
commit
0c9dc07479
6 changed files with 21 additions and 8 deletions
1
Makefile
1
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 \
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
6
frontend/index.html
vendored
6
frontend/index.html
vendored
|
@ -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>
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue