Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6e20242

Browse files
committed
fix: make non-existent asset paths return a 404
Before, if a file was not found we would serve the app.
1 parentf24cb5c commit6e20242

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

‎site/site.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,17 @@ func (h *Handler) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
205205
casereqFile=="bin"||strings.HasPrefix(reqFile,"bin/"):
206206
h.handler.ServeHTTP(rw,r)
207207
return
208+
// If requesting assets, serve straight up with caching.
209+
casereqFile=="assets"||strings.HasPrefix(reqFile,"assets/"):
210+
// It could make sense to cache 404s, but the problem is that during an
211+
// upgrade a load balance may route partially to the old server, and that
212+
// would make new asset paths get cached as 404s and not load even once the
213+
// new server was in place. To combat that, only cache if we have the file.
214+
ifh.exists(reqFile)&&ShouldCacheFile(reqFile) {
215+
rw.Header().Add("Cache-Control","public, max-age=31536000, immutable")
216+
}
217+
h.handler.ServeHTTP(rw,r)
218+
return
208219
// If the original file path exists we serve it.
209220
caseh.exists(reqFile):
210221
ifShouldCacheFile(reqFile) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp