Skip to content

[Support request] A question about initialization at client size #3

Description

@acrolink

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions