Combine existense and date checks.

pull/468/head
Chad Weider 2012-02-19 17:34:43 -08:00
parent a5006255b7
commit ff264aa69a
1 changed files with 30 additions and 46 deletions

View File

@ -54,7 +54,7 @@ exports.minifyJS = function(req, res, next)
var filename = req.params['filename'];
res.header("Content-Type","text/javascript");
lastModifiedDateOf(filename, function (error, date) {
statFile(filename, function (error, date, exists) {
date = new Date(date);
res.setHeader('last-modified', date.toUTCString());
res.setHeader('date', (new Date()).toUTCString());
@ -64,7 +64,6 @@ exports.minifyJS = function(req, res, next)
res.setHeader('cache-control', 'max-age=' + server.maxAge);
}
fileExists(filename, function (error, exists) {
if (error) {
res.writeHead(500, {});
res.end();
@ -91,7 +90,6 @@ exports.minifyJS = function(req, res, next)
}
}
});
});
}
// find all includes in ace.js and embed them.
@ -161,9 +159,11 @@ function getAceFile(callback) {
});
}
function lastModifiedDateOf(filename, callback) {
function statFile(filename, callback) {
if (filename == 'ace.js') {
lastModifiedDateOfEverything(callback);
lastModifiedDateOfEverything(function (error, date) {
callback(error, date, !error);
});
} else {
fs.stat(JS_DIR + filename, function (error, stats) {
if (error) {
@ -171,15 +171,17 @@ function lastModifiedDateOf(filename, callback) {
fs.stat(JS_DIR, function (error, stats) {
if (error) {
callback(error);
} else if (filename == 'require-kernel.js') {
callback(null, stats.mtime.getTime(), true);
} else {
callback(null, stats.mtime.getTime());
callback(null, stats.mtime.getTime(), false);
}
});
} else {
callback(error);
}
} else {
callback(null, stats.mtime.getTime());
callback(null, stats.mtime.getTime(), true);
}
});
}
@ -255,24 +257,6 @@ function getFile(filename, callback) {
}
}
function fileExists(filename, callback) {
if (filename == 'require-kernel.js') {
callback(undefined, true);
} else {
fs.stat(JS_DIR + filename, function (error, stats) {
if (error) {
if (error.code == "ENOENT") {
callback(undefined, false);
} else {
callback(error, undefined);
}
} else {
callback(undefined, stats.isFile());
}
});
}
}
function tarCode(jsFiles, write, callback) {
write('require.define({');
var initialEntry = true;