john doe john doe - 1 year ago 122
HTTP Question

koa-static not following max-age

I am using koa-static to serve my assets.
I have set max-age to a minute for now 60000ms (as described in the docs)

For testing purposes, I am using a big image as a background in my page, but it seems that the browser still re-downloads it every time the page is opened anyway...

Here is the related code:

var app = require('koa')(),
serve = require('koa-static');

app.use(serve('./public', {
maxage: 60000,

How can I fix this?

Answer Source

Are you sure this is not a problem with your browser instead of koa-static? I tried your example as is, but instead of using a browser i used curl to check out the headers:

if you curl -I http://localhost:3000/img.png

You will see that the max-age header is set to one minute as desired. It seems the cache-control was set to what we wanted, so it must be your browser doing something tricky with the headers. For example, if you are using chrome, it will set max-age=0 in certain situations:

Chrome doesn't cache images/js/css

Hope this helps!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download