1

Most of the WebSocket examples out there are centered around a single web page, where the content updates with chat, financial or some other live metrics - makes sense for a single page.

However, given a news feed scroller, where that feed needs to exist on every page of the site, I would like to open the conversation up to some possibilities for this.

Currently the site is a classic ASP site, but will be eventually migrated to MVC/MVP.

Since we don't want to open/close the web socket every time a link is clicked on (currently loads a new page), I was thinking about an IFrame type of UI, which can be done with updatable DIV's and jQuery.

Given a simple containerized UI template with a header (c1) and footer (c2), content in the center (c3) with left (c4) and right (c5) bars, when clicking on a link on the header, where the main menu would reside, instead of updating the entire page, I could load a page into one of the containers (updatable div), preserving the WebSocket container's connection - avoiding needing to re-establish the connection.

What are some other options to consider to accomplish this?

Thanks.

UPDATE

If you take a look at FB's implementation, their status bar on the right and even chat, stay on the page across link clicks. How is that accomplished?

ElHaix
  • 12,846
  • 27
  • 115
  • 203

1 Answers1

0

Using IFrames or otherwise modifying your page state (rather than full page loads) is probably the best direction right now but shared Workers may also do what you want. The idea is to allow multiple pages loaded simultaneously from the same origin to share a web worker. I suspect that the shared worker will persist even for page navigation within the same site. However, I have not actually tried it and the W3C spec is not clear to me on this issue. I would be interested to know if this is in fact true.

Note that Shared Workers are in Chrome, Safari and Opera but IE and Firefox have not committed to supporting shared workers yet:

kanaka
  • 70,845
  • 23
  • 144
  • 140
  • I created a new question to address the persistence of shared workers: http://stackoverflow.com/questions/9336774/do-shared-web-workers-persist-across-a-single-page-reload-link-navigation – kanaka Feb 17 '12 at 23:16
  • So, at present, and based on what I read in the responses from your new question, the using web workers, we cannot guarantee that the connection will be kept open across multiple web page requests. Therefore a using frames or updatable DIVs would be the best solution. I suppose you could simulate a worker by keeping another window open that maintains the websocket connection and writes to the parent window/frame... messy though. – ElHaix Feb 22 '12 at 15:34
  • @ElHaix, yeah, if you want a single answer that works in several places, I think that's probably the best direction right now. If you have time/resources, then exploring Shared Workers might be worth it for certain users that have the capability. – kanaka Feb 22 '12 at 16:52