diff --git a/cmd/packserver/main.go b/cmd/packserver/main.go index c51ba00..a374a66 100644 --- a/cmd/packserver/main.go +++ b/cmd/packserver/main.go @@ -57,6 +57,8 @@ func main() { "Tell client how long it can cache data for; 0 means no caching") rootCmd.Flags().Duration("expiry404", 0, "Tell client how long it can cache 404 responses for; 0 means default (inherit from --expiry, max. 60s); -1 means no caching") + rootCmd.Flags().Bool("immutable", false, + "Tell client that cached assets are immutable (will not be revalidated on page reload)") rootCmd.Flags().String("fallback-404", "", "Name of file to return if response would be 404 (spa.html or similar)") rootCmd.Flags().String("frames", "sameorigin", @@ -138,12 +140,21 @@ func run(c *cobra.Command, args []string) error { // parse expiry time // NB: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control cacheControl200, cacheControl404 := "no-cache", "no-cache" + immutable, err := c.Flags().GetBool("immutable") + if err != nil { + return err + } + var immutableDirective string + if immutable { + immutableDirective = ", immutable" + } + expiry, err := c.Flags().GetDuration("expiry") if err != nil { return err } if expiry > 0 { - cacheControl200 = fmt.Sprintf("public, max-age=%d", expiry/1e9) + cacheControl200 = fmt.Sprintf("public, max-age=%d%s", expiry/1e9, immutableDirective) } expiry404, err := c.Flags().GetDuration("expiry404")