HTML5 WebSocket w/ Relative URL
I have been toying with the new WebSocket APIs in HTML5. This is a fantastic feature of the latest generation web standards that gives developers the ability to do two-way, streaming network communication directly in the web-browser from JavaScript. WebSockets have the potential to revolutionize performance of web applications, and so, revolutionize the ability of developers to offer rich, user-friendly and useful solutions to our clientele.
The current state of WebSocket development is that modern web-browser makers are all providing excellent WebSocket functionality. I tested with Microsoft IE 10, Mozilla Firefox 20, Google Chrome 25. All three browsers worked identically without any special cross-browser hacks. The server-side prognosis also seems good. Most of my dabbling has been with Tomcat's built in WebSocket support, but it seemed very solid. I was less pleased to learn that Apache HTTPD does not support proxing WebSocket requests via AJP or mod_proxy.
Tip of the day:
One of the quirks of the WebSocket API is that in order to create a new WebSocket object, you MUST pass a FQDN URL such as:
wss://my.domain/MyWebSocketService
However
window.location.href.replace(/^http(s?:\/\/.*)\/.*$/, 'ws$1/SpikeWebSocketServlet')