Catch 304's early.

This commit is contained in:
Chad Weider 2012-01-29 00:00:11 -08:00
parent d6d4178dbc
commit c2669360d1
1 changed files with 19 additions and 12 deletions

View File

@ -70,20 +70,27 @@ exports.minifyJS = function(req, res, next)
function _handle(req, res, jsFilename, jsFiles) {
res.header("Content-Type","text/javascript");
//minifying is enabled
if(settings.minify)
lastModifiedDate(function (date) {
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 latestModification = 0;
var latestModification = new Date(res.getHeader('last-modified'));
async.series([
//find out the highest modification date
function (callback) {
lastModifiedDate(function (date) {
latestModification = date;
callback()
});
},
function(callback)
{
//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
else
function respondRaw()
{
tarCode(
jsFiles