Created
January 29, 2014 20:55
-
-
Save mustafaakin/8696860 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'); | |
var http = require('http'); | |
var path = require('path'); | |
var fs = require("fs"); | |
var jade = require("jade"); | |
var app = express(); | |
app.set('port', process.env.PORT || 3000); | |
app.set('views', path.join(__dirname, 'views')); | |
app.set('view engine', 'jade'); | |
app.use(express.methodOverride()); | |
var data = []; | |
for (var i = 0; i < 25; i++) { | |
data.push({ | |
idx: i, | |
text: new Buffer(50).toString("base64") | |
}); | |
} | |
// Plain Rendering | |
app.get("/normal", function(req, res) { | |
res.render("index.jade", { | |
data: data | |
}); | |
}); | |
// Read file only ONCE | |
var file = fs.readFileSync("views/index.jade"); | |
app.get("/halfoptimized", function(req, res) { | |
res.end(jade.render(file, { | |
data: data | |
})); | |
}); | |
// Compile the template, so no need to parse it over and over again | |
var fn = jade.compile(file); | |
app.get("/optimized", function(req, res) { | |
res.end(fn({ | |
data: data | |
})); | |
}); | |
app.listen(5000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment