title: How keep a Websocket connection persistent, even after page refresh?
body: <p>I have a web application where a <strong>persistent connection</strong> from the server to it's clients (browser) is needed in order <strong>push news / updates to the clients</strong> in (near) real-time.  This would not be so tricky if the navigation through some elements of the website <strong>would not cause complete page refreshs</strong>.</p>
  
  <p>Polling (standard way or long polling) the server for news is not an option, since it results in often unnecessary request calls (because no news are available). Moreover news can rise up randomly. Therefore with the polling strategy the server would go down...
  For the websocket (bidirectional communication channel) the client and server have to accept the upgrade to websocket.
  A similar problem was discussed <a href="https://stackoverflow.com/questions/10886910/how-to-maintain-a-websockets-connection-between-pages">here</a>, but no satisfying solution was found.</p>
  
  <p>Data can survive a full page refresh by storing it in cookies or other ways:</p>
  
  <ul>
  <li>cookies</li>
  <li>window.name (www.thomasfrank.se/sessionvars.html)</li>
  <li>localstorage: stores the data with no expiration date. The data will not be deleted
  when the browser is closed. Example: Perseverance (github.com/viseztrance/perseverance)</li>
  <li>PersistJS: Cross Browser Client-Side Persistent Storage without cookies Storing the
  Javascript object is done, by serialize / deserialize the object.</li>
  </ul>
  
  <p>Is there something that works similar for „running“ objects like websockets?</p>
  
  <p>Some possibilities I thought of, are:</p>
  
  <ul>
  <li>An old style „solution“ would be to put the whole web application in an iFrame and add the connection to the outermost window (of the frame). This is not an option since it causes a lot of different other problems. </li>
  <li>Since HTML5 <a href="http://www.sitepoint.com/javascript-shared-web-workers-html5/" rel="nofollow noreferrer">Share Web Workers</a> exits, but because of the limited browser support this can also not be used.</li>
  </ul>
  
  <p>So my question is: Is there a possibility / hack how I can keep my websocket connection open also if the page is refreshed? So that I don't have to reinitialize the connection to the server?</p>