From a5006255b7f4a6454dc2368b597ec44de824d3da Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Sun, 5 Feb 2012 15:01:51 -0800 Subject: [PATCH] Last modification is more specific (when possible). --- node/utils/Minify.js | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/node/utils/Minify.js b/node/utils/Minify.js index 204fd15d7..ef2117c37 100644 --- a/node/utils/Minify.js +++ b/node/utils/Minify.js @@ -54,7 +54,7 @@ exports.minifyJS = function(req, res, next) var filename = req.params['filename']; res.header("Content-Type","text/javascript"); - lastModifiedDate(function (date) { + lastModifiedDateOf(filename, function (error, date) { date = new Date(date); res.setHeader('last-modified', date.toUTCString()); res.setHeader('date', (new Date()).toUTCString()); @@ -161,7 +161,30 @@ function getAceFile(callback) { }); } -function lastModifiedDate(callback) { +function lastModifiedDateOf(filename, callback) { + if (filename == 'ace.js') { + lastModifiedDateOfEverything(callback); + } else { + fs.stat(JS_DIR + filename, function (error, stats) { + if (error) { + if (error.code == "ENOENT") { // Stat the directory instead. + fs.stat(JS_DIR, function (error, stats) { + if (error) { + callback(error); + } else { + callback(null, stats.mtime.getTime()); + } + }); + } else { + callback(error); + } + } else { + callback(null, stats.mtime.getTime()); + } + }); + } +} +function lastModifiedDateOfEverything(callback) { var folders2check = [CSS_DIR, JS_DIR]; var latestModification = 0; //go trough this two folders @@ -197,7 +220,7 @@ function lastModifiedDate(callback) { }, callback); }); }, function () { - callback(latestModification); + callback(null, latestModification); }); }