Permalink
Browse files

Catch 304's early.

  • Loading branch information...
1 parent d6d4178 commit c2669360d1f6333066af95bc5c8420d190cf239a @cweider committed Jan 29, 2012
Showing with 19 additions and 12 deletions.
  1. +19 −12 node/utils/Minify.js
View
31 node/utils/Minify.js
@@ -69,21 +69,28 @@ 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

0 comments on commit c266936

Please sign in to comment.