Catch 304's early.

This commit is contained in:
Chad Weider 2012-01-29 00:00:11 -08:00
parent d6d4178dbc
commit c2669360d1

View file

@ -70,20 +70,27 @@ exports.minifyJS = function(req, res, next)
function _handle(req, res, jsFilename, jsFiles) { function _handle(req, res, jsFilename, jsFiles) {
res.header("Content-Type","text/javascript"); res.header("Content-Type","text/javascript");
//minifying is enabled lastModifiedDate(function (date) {
if(settings.minify) date = new Date(date);
res.setHeader('last-modified', date.toUTCString());
res.setHeader('date', (new Date()).toUTCString());
if (new Date(req.headers['if-modified-since']) >= date) {
res.writeHead(304, {});
res.end();
} else if (settings.minify) {
respondMinified();
} else {
respondRaw();
}
});
function respondMinified()
{ {
var result = undefined; var result = undefined;
var latestModification = 0; var latestModification = new Date(res.getHeader('last-modified'));
async.series([ async.series([
//find out the highest modification date
function (callback) {
lastModifiedDate(function (date) {
latestModification = date;
callback()
});
},
function(callback) function(callback)
{ {
//check the modification time of the minified js //check the modification time of the minified js
@ -169,7 +176,7 @@ function _handle(req, res, jsFilename, jsFiles) {
}) })
} }
//minifying is disabled, so put the files together in one file //minifying is disabled, so put the files together in one file
else function respondRaw()
{ {
tarCode( tarCode(
jsFiles jsFiles