@@ -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 }))
0 commit comments