diff --git a/lib/plugins/static.js b/lib/plugins/static.js index adb82a3c..cf71101e 100644 --- a/lib/plugins/static.js +++ b/lib/plugins/static.js @@ -51,6 +51,19 @@ function serveStatic(options) { return; } + if(req.headers['if-modified-since']) + { + var fromBrowser = new Date(req.headers['if-modified-since']); + var fromDrive = new Date(stats.mtime); + fromDrive.setMilliseconds(0); + + if(fromBrowser.getTime() >= fromDrive.getTime()) + { + res.send(304); + return next(false); + } + } + if (res.handledGzip && isGzip) { res.handledGzip(); } @@ -59,6 +72,9 @@ function serveStatic(options) { var maxAge = opts.maxAge === undefined ? 3600 : opts.maxAge; fstream.once('open', function (fd) { res.cache({maxAge: maxAge}); + if(maxAge) { + res.set("Expires", new Date(Date.now() + maxAge*1000).toUTCString()); + } res.set('Content-Length', stats.size); res.set('Content-Type', mime.lookup(file)); res.set('Last-Modified', stats.mtime);