title: How to make a constant script on html page
body: <p>I know the title sounds a little weird but the following will explain it,</p>
  
  <p>I have a website with php chat script with javascript timer to refresh messages each 5 seconds, which makes it so annoying.</p>
  
  <p>I'm planning to switch to nodejs and make a real-time chat app.</p>
  
  <p>To connect the user to the server i'm using the following : </p>
  
  <pre><code>&lt;script&gt;
      var c = new WebSocket("ws://localhost:8001");
  &lt;/script&gt;
  </code></pre>
  
  <p>This script is necessary on every page for the user to stay connected, but the problem is that it's gonna create a new websocket each time which is bad for the performance and load time, i've noticed on facebook that the navigation bar and chat bar does not reload when navigating, so how to achieve that ?</p>
  
  <p>Thanks in advance</p>