Skip to content

Instantly share code, notes, and snippets.

@mustafaakin

mustafaakin/app.js

Created Jan 29, 2014
Embed
What would you like to do?
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
You can’t perform that action at this time.