browserify-cache
Advanced tools
Comparing version 0.1.0 to 0.1.1
13
index.js
@@ -1,6 +0,8 @@ | ||
var browserify = require('browserify'); | ||
module.exports = function(browserifyOpts, browserifyMiddleware) { | ||
var lastModified = browserifyMiddleware.modified.getTime(); | ||
return function(req, res, next) { | ||
//Pass a fake request through browserify so that we can update the bundle if it has changed | ||
browserifyMiddleware({'url': browserifyOpts.mount}, {'setHeader': function() { | ||
console.log("browserify:setHeader", arguments); | ||
}, 'end': function() {}} ); | ||
if(lastModified != browserifyMiddleware.modified.getTime() ) | ||
@@ -14,3 +16,3 @@ { | ||
{ | ||
//Add expires header | ||
//Add expires header - maximum recommended expiration is one year | ||
var d = new Date(); | ||
@@ -24,3 +26,3 @@ d.setFullYear(d.getFullYear() + 1); | ||
//Check If-Modified-Since request header | ||
if(new Date(req.headers["if-modified-since"]).getTime() == browserifyMiddleware.modified.getTime() ) | ||
if(Math.floor(new Date(req.headers["if-modified-since"]).getTime() / 1000) == Math.floor(browserifyMiddleware.modified.getTime() / 1000) ) | ||
res.send(304); | ||
@@ -31,2 +33,5 @@ else | ||
req.url = browserifyOpts.mount; //Trick browserify | ||
console.log("Browserify is handling this request"); | ||
console.log("\tif-modified-since:", req.headers["if-modified-since"], new Date(req.headers["if-modified-since"]).getTime() ); | ||
console.log("\tbrowserify modified date:", browserifyMiddleware.modified, browserifyMiddleware.modified.getTime()); | ||
browserifyMiddleware(req, res, next); | ||
@@ -33,0 +38,0 @@ } |
@@ -5,3 +5,3 @@ { | ||
"description": "Easily cache Browserify bundles", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"repository": { | ||
@@ -13,3 +13,3 @@ "type": "git", | ||
"engines": { | ||
"node": "~0.4.12" | ||
"node": ">0.4.9" | ||
}, | ||
@@ -16,0 +16,0 @@ "dependencies": {}, |
3418
39
29