node-and-socket-example
node-and-socket-example copied to clipboard
[Support request] A question about initialization at client size
Thanks for the tutorial. I have a basic socket.io question that I hope you can help me with. I understand that the connection to the remote server gets initialized by:
var socket = io.connect();
socket.on('date', function(data){
$('#date').text(data.date);
});
My question, does this piece of code have to be called and re-called on every page load at my site i.e. while the user navigates the site or could I declare some global socket variable that will establish the connection as the user makes the first page load request (e.g. as he visits root URL path) and that's it?
Because the code as I read it above is called on every page load / navigation on site, which means the remote server is contacted all the time as the user navigates the site, which looks for me as an overkill. Any input regarding my question is highly appreciated.