aboutsummaryrefslogtreecommitdiffstats
path: root/templates
diff options
context:
space:
mode:
authorsilverwind <me@silverwind.io>2022-08-23 14:58:04 +0200
committerGitHub <noreply@github.com>2022-08-23 20:58:04 +0800
commit56220515fc882943e366fafbce4d5b2b3ccee702 (patch)
treed64bffc3a9d13ce01bf56aedc896923aa4af0acf /templates
parent0a9ed54abbe8b6837dcb22a35b744c11f410421f (diff)
downloadgitea-56220515fc882943e366fafbce4d5b2b3ccee702.tar.gz
gitea-56220515fc882943e366fafbce4d5b2b3ccee702.zip
Enable contenthash in filename for dynamic assets (#20813)
This should solve the main problem of dynamic assets getting stale after a version upgrade. Everything not affected will use query-string based cache busting, which includes files loaded via HTML or worker scripts.
Diffstat (limited to 'templates')
-rw-r--r--templates/base/footer.tmpl2
-rw-r--r--templates/base/head.tmpl6
-rw-r--r--templates/base/head_script.tmpl1
-rw-r--r--templates/swagger/ui.tmpl4
4 files changed, 7 insertions, 6 deletions
diff --git a/templates/base/footer.tmpl b/templates/base/footer.tmpl
index 9bf16f8aa5..0e1b382d9d 100644
--- a/templates/base/footer.tmpl
+++ b/templates/base/footer.tmpl
@@ -22,7 +22,7 @@
<script src='https://hcaptcha.com/1/api.js' async></script>
{{end}}
{{end}}
- <script src="{{AssetUrlPrefix}}/js/index.js?v={{MD5 AppVer}}" onerror="alert('Failed to load asset files from ' + this.src + ', please make sure the asset files can be accessed and the ROOT_URL setting in app.ini is correct.')"></script>
+ <script src="{{AssetUrlPrefix}}/js/index.js?v={{AssetVersion}}" onerror="alert('Failed to load asset files from ' + this.src + ', please make sure the asset files can be accessed and the ROOT_URL setting in app.ini is correct.')"></script>
{{template "custom/footer" .}}
</body>
</html>
diff --git a/templates/base/head.tmpl b/templates/base/head.tmpl
index e0d2b26f2c..233cf3e1d5 100644
--- a/templates/base/head.tmpl
+++ b/templates/base/head.tmpl
@@ -21,7 +21,7 @@
{{end}}
<link rel="icon" href="{{AssetUrlPrefix}}/img/favicon.svg" type="image/svg+xml">
<link rel="alternate icon" href="{{AssetUrlPrefix}}/img/favicon.png" type="image/png">
- <link rel="stylesheet" href="{{AssetUrlPrefix}}/css/index.css?v={{MD5 AppVer}}">
+ <link rel="stylesheet" href="{{AssetUrlPrefix}}/css/index.css?v={{AssetVersion}}">
{{template "base/head_script" .}}
<noscript>
<style>
@@ -67,10 +67,10 @@
<meta property="og:site_name" content="{{AppName}}">
{{if .IsSigned }}
{{ if ne .SignedUser.Theme "gitea" }}
- <link rel="stylesheet" href="{{AssetUrlPrefix}}/css/theme-{{.SignedUser.Theme | PathEscape}}.css?v={{MD5 AppVer}}">
+ <link rel="stylesheet" href="{{AssetUrlPrefix}}/css/theme-{{.SignedUser.Theme | PathEscape}}.css?v={{AssetVersion}}">
{{end}}
{{else if ne DefaultTheme "gitea"}}
- <link rel="stylesheet" href="{{AssetUrlPrefix}}/css/theme-{{DefaultTheme | PathEscape}}.css?v={{MD5 AppVer}}">
+ <link rel="stylesheet" href="{{AssetUrlPrefix}}/css/theme-{{DefaultTheme | PathEscape}}.css?v={{AssetVersion}}">
{{end}}
{{template "custom/header" .}}
</head>
diff --git a/templates/base/head_script.tmpl b/templates/base/head_script.tmpl
index 48a3df693a..a74923b55f 100644
--- a/templates/base/head_script.tmpl
+++ b/templates/base/head_script.tmpl
@@ -9,6 +9,7 @@ If you introduce mistakes in it, Gitea JavaScript code wouldn't run correctly.
appVer: '{{AppVer}}',
appUrl: '{{AppUrl}}',
appSubUrl: '{{AppSubUrl}}',
+ assetVersionEncoded: encodeURIComponent('{{AssetVersion}}'), // will be used in URL construction directly
assetUrlPrefix: '{{AssetUrlPrefix}}',
runModeIsProd: {{.RunModeIsProd}},
customEmojis: {{CustomEmojis}},
diff --git a/templates/swagger/ui.tmpl b/templates/swagger/ui.tmpl
index 1791e234ea..d4d0889f9d 100644
--- a/templates/swagger/ui.tmpl
+++ b/templates/swagger/ui.tmpl
@@ -3,11 +3,11 @@
<head>
<meta charset="UTF-8">
<title>Gitea API</title>
- <link href="{{AssetUrlPrefix}}/css/swagger.css?v={{MD5 AppVer}}" rel="stylesheet">
+ <link href="{{AssetUrlPrefix}}/css/swagger.css?v={{AssetVersion}}" rel="stylesheet">
</head>
<body>
<a class="swagger-back-link" href="{{AppUrl}}">{{svg "octicon-reply"}}{{.locale.Tr "return_to_gitea"}}</a>
<div id="swagger-ui" data-source="{{AppUrl}}swagger.{{.APIJSONVersion}}.json"></div>
- <script src="{{AssetUrlPrefix}}/js/swagger.js?v={{MD5 AppVer}}"></script>
+ <script src="{{AssetUrlPrefix}}/js/swagger.js?v={{AssetVersion}}"></script>
</body>
</html>