Two related questions that may be more rooted in my lack of knowledge of how/if browsers pre-parse javascript:
var ws = new WebSocket(\"ws://ws.my.url.com\")
No actual I/O will happen until after your script finishes executing, so there should not be a race condition.