lukeed / sirv

An optimized middleware & CLI application for serving static files~!
MIT License
1.07k stars 58 forks source link

Dev mode with cache control #152

Open axmad386 opened 1 year ago

axmad386 commented 1 year ago

I know in the docs that with dev = true it will traverse the file system on every request. Is it possible to use dev mode but the http response still set the cache control? It will useful when we want to make public folder contain dynamic asset, we can add another asset to it, but when we access it browser will cache it.

axmad386 commented 1 year ago

My workaround is to set dev to true and manage cache control via setHeader something like this

 sirv(public_path(),{
      dev:true,
      setHeaders: (res) => {
        res.setHeader("Cache-Control", "public,max-age=31536000,immutable");
      },
})

this will make sirv still serve the file dynamically but cache control is sent. So browser will cache the file