Skip to content

Commit a4fd621

Browse files
committed
Enable contenthash in filename for dynamic assets (go-gitea#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 6779c35 commit a4fd621

15 files changed

+1187
-3210
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
@@ -91,6 +91,8 @@ var (
9191
// LocalURL is the url for locally running applications to contact Gitea. It always has a '/' suffix
9292
// It maps to ini:"LOCAL_ROOT_URL"
9393
LocalURL string
94+
// AssetVersion holds a opaque value that is used for cache-busting assets
95+
AssetVersion string
9496

9597
// Server settings
9698
Protocol Scheme
@@ -749,6 +751,7 @@ func loadFromConf(allowEmpty bool, extraConfig string) {
749751
}
750752

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

753756
manifestBytes := MakeManifestData(AppName, AppURL, AbsoluteAssetURL)
754757
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
},
@@ -151,7 +154,6 @@ func NewFuncMap() []template.FuncMap {
151154
"DiffTypeToStr": DiffTypeToStr,
152155
"DiffLineTypeToStr": DiffLineTypeToStr,
153156
"ShortSha": base.ShortSha,
154-
"MD5": base.EncodeMD5,
155157
"ActionContent2Commits": ActionContent2Commits,
156158
"PathEscape": url.PathEscape,
157159
"PathEscapeSegments": util.PathEscapeSegments,

0 commit comments

Comments
 (0)