Skip to content

Instantly share code, notes, and snippets.

@ntotten
Created October 7, 2012 03:54
Show Gist options
  • Select an option

  • Save ntotten/3847038 to your computer and use it in GitHub Desktop.

Select an option

Save ntotten/3847038 to your computer and use it in GitHub Desktop.
Building Super Fast Web Apps with PJAX
$('a.pjax').pjax('#main')
$('#main')
.on('pjax:start', function() { $('#loading').show() })
.on('pjax:end', function() { $('#loading').hide() })
<a href='/explore' data-pjax='#main'>Explore</a>
$('a[data-pjax]').pjax()
module.exports = function() {
return function(req, res, next) {
if (req.header('X-PJAX')) {
req.pjax = true;
}
res.renderPjax = function(view, options, fn) {
if (req.pjax) {
if (options) {
options.layout = false;
} else {
options = {};
options.layout = false;
}
}
res.render(view, options, fn);
};
next();
};
};
module.exports = function(app) {
app.get('/', function(req, res) {
res.renderPjax('home/index', { title: 'SocialDrawing' });
});
app.get('/about', function(req, res) {
res.renderPjax('home/about', { title: 'About' });
});
app.get('/contact', function(req, res) {
res.renderPjax('home/contact', { title: 'Contact' });
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment