spaBuildCacheMiddleware sets cache headers for SPA build assets: - "index.js" / "main.css" (unhashed entry points the shell HTML loads by name) → no-cache, so browsers always pick up new chunk references after a deploy. - everything else (content-hashed chunks, immutable assets) → long-lived immutab
()
| 19 | // - everything else (content-hashed chunks, immutable assets) → long-lived |
| 20 | // immutable cache, since a content change produces a new filename. |
| 21 | func spaBuildCacheMiddleware() gin.HandlerFunc { |
| 22 | return func(c *gin.Context) { |
| 23 | base := path.Base(c.Request.URL.Path) |
| 24 | if base == "index.js" || base == "main.css" { |
| 25 | c.Header("Cache-Control", "no-cache, must-revalidate") |
| 26 | } else { |
| 27 | c.Header("Cache-Control", "public, max-age=31536000, immutable") |
| 28 | } |
| 29 | c.Next() |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | // NewRouter creates new gin router |
| 34 | func (s *server) NewRouter() *gin.Engine { |