Skip to content

Commit 5622051

Browse files
authored
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.
1 parent 0a9ed54 commit 5622051

15 files changed

+1146
-846
lines changed

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export default {
22
rootDir: 'web_src',
33
setupFilesAfterEnv: ['jest-extended/all'],
4-
testEnvironment: '@happy-dom/jest-environment',
4+
testEnvironment: 'jest-environment-jsdom',
55
testMatch: ['<rootDir>/**/*.test.js'],
66
testTimeout: 20000,
77
transform: {

modules/setting/setting.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ var (
9292
// LocalURL is the url for locally running applications to contact Gitea. It always has a '/' suffix
9393
// It maps to ini:"LOCAL_ROOT_URL"
9494
LocalURL string
95+
// AssetVersion holds a opaque value that is used for cache-busting assets
96+
AssetVersion string
9597

9698
// Server settings
9799
Protocol Scheme
@@ -759,6 +761,7 @@ func loadFromConf(allowEmpty bool, extraConfig string) {
759761
}
760762

761763
AbsoluteAssetURL = MakeAbsoluteAssetURL(AppURL, StaticURLPrefix)
764+
AssetVersion = strings.ReplaceAll(AppVer, "+", "~") // make sure the version string is clear (no real escaping is needed)
762765

763766
manifestBytes := MakeManifestData(AppName, AppURL, AbsoluteAssetURL)
764767
ManifestData = `application/json;base64,` + base64.StdEncoding.EncodeToString(manifestBytes)

modules/templates/helper.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ func NewFuncMap() []template.FuncMap {
8181
"AppDomain": func() string {
8282
return setting.Domain
8383
},
84+
"AssetVersion": func() string {
85+
return setting.AssetVersion
86+
},
8487
"DisableGravatar": func() bool {
8588
return setting.DisableGravatar
8689
},
@@ -150,7 +153,6 @@ func NewFuncMap() []template.FuncMap {
150153
"DiffTypeToStr": DiffTypeToStr,
151154
"DiffLineTypeToStr": DiffLineTypeToStr,
152155
"ShortSha": base.ShortSha,
153-
"MD5": base.EncodeMD5,
154156
"ActionContent2Commits": ActionContent2Commits,
155157
"PathEscape": url.PathEscape,
156158
"PathEscapeSegments": util.PathEscapeSegments,

0 commit comments

Comments
 (0)