i m creating site on nodejs (0.8.15) and express framework (>3.0) there will be user registration, many chats, send private messages, some online games, using socket.io and so on..
1) if user amount at one time is 5000+ users online, how should i load pages to make my site fast: to load page simply with render
app.get('/', function(req, res) {
res.render('anypage');
}
and app.post('/', ..)
or with
$.ajax({ url: '/'
, type: 'GET/POST'
, dataType: 'html'
})
.done(function(data) {
$('#content').load('anypage.html');
});
?
Honestly, i want to make single-page app, but i worry about the performance and speed.
2) or maybe is there another way to load pages faster?
thank you!
1) Your choices are... strange. app.get
is on the server side, while $.ajax
on client side. I assume that you are talking about AJAX vs classical links, URLs. But the thing is that using single-page app does not affect performance at all, at least not out of the box. It all depends on how you implement it.
But generally AJAX is more efficient, because you don't have to download the same HTML ( base layout ) and/or images every time. It is also more user friendly, because there are no "blinks" when going from one page to another. On the other hand it is harder to implement cross-browser single-page apps. The difficulty is even higher when you are dealing with dynamic script loading and/or browser history.
2) There are thousands of techniques for improving loading speed. But most of them base on the proper caching and horizontal scaling.
I think you should focus on the node layer serving JSON via an api and using a client side framework like Backbone.js + jQuery to render the pages. It will push most of the heavy lifting of the UI to the client, instead of the server.