Skip to content

Commit 5d4dc7f

Browse files
committed
Stop browsers from caching index.html files
1 parent 1872666 commit 5d4dc7f

3 files changed

Lines changed: 25 additions & 0 deletions

File tree

backend/cmd/server/main.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,9 @@ func createStaticFileHandler(routePrefix, directory string, logger *log.Logger)
306306
// Get the file path
307307
filePath := path.Join(directory, r.URL.Path)
308308

309+
// Check if the requested file is index.html or if we need to serve it as fallback
310+
isIndexHTML := r.URL.Path == "/" || r.URL.Path == "/index.html" || strings.HasSuffix(filePath, "index.html")
311+
309312
// Check if file exists
310313
if _, err := os.Stat(filePath); os.IsNotExist(err) {
311314
// For SPA routing, serve index.html for non-existent files
@@ -314,11 +317,22 @@ func createStaticFileHandler(routePrefix, directory string, logger *log.Logger)
314317
logger.Debug("Serving index.html for SPA routing",
315318
log.String("requested_path", r.URL.Path),
316319
log.String("route_prefix", routePrefix))
320+
// Set no-cache headers for index.html
321+
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
322+
w.Header().Set("Pragma", "no-cache")
323+
w.Header().Set("Expires", "0")
317324
http.ServeFile(w, r, indexPath)
318325
return
319326
}
320327
}
321328

329+
// Set no-cache headers for index.html when served directly
330+
if isIndexHTML {
331+
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
332+
w.Header().Set("Pragma", "no-cache")
333+
w.Header().Set("Expires", "0")
334+
}
335+
322336
// Serve the requested file or directory listing
323337
fileServer.ServeHTTP(w, r)
324338
}))

frontend/apps/thunder-develop/index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
<link rel="icon" type="image/x-icon" href="/assets/images/favicon.ico" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
77

8+
<!-- Prevent browser caching -->
9+
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
10+
<meta http-equiv="Pragma" content="no-cache" />
11+
<meta http-equiv="Expires" content="0" />
12+
813
<!-- Start of loading application configurations -->
914
<script type="text/javascript" src="/config.js"></script>
1015
<!-- End of loading application configurations -->

frontend/apps/thunder-gate/index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
<meta charset="UTF-8" />
55
<link rel="icon" type="image/x-icon" href="/assets/images/favicon.ico" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
8+
<!-- Prevent browser caching -->
9+
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
10+
<meta http-equiv="Pragma" content="no-cache" />
11+
<meta http-equiv="Expires" content="0" />
12+
713
<title>Gate</title>
814

915
<!-- Start of loading application configurations -->

0 commit comments

Comments
 (0)