Contact Us
Free Trial
Secure Video Conferencing LiveSwitch Cloud
Secure Video Conferencing LiveSwitch Cloud

Delayed Client Loading with WebSync and jQuery

by Frozen Mountain Software, on August 17, 2010

Warning: technical content ahead!

Recently, we were recently doing some work for a client when we came across a minor problem. We were building an application that had a bit of a unique requirement: the entire application had to work with the inclusion of a single <script> tag. Scripts could be added dynamically, but the end user had to only see a single tag.

"Simple enough", we thought; we'll simply combine the JS and CSS server-side, and be done with it. Of course, that would have meant manually extracting the JavaScript for the WebSync client from the server code. Now, that's not difficult to do (it's just an embedded resource), but we were curious if there was an even simpler solution. An extra request was completely acceptable, and since we were already using jQuery, we figured we'd just use that to load the script. The result was this:

$(function(){
$.getScript("/client.ashx", function(){
client.initialize();
client.connect();
// ...etc
});
});

"Great", we thought. Problem solved. But then we realized that none of our client requests were being sent anymore! We pondered for a moment, and then remembered that the WebSync client is designed to monitor the "contentReady" event of the DOM so as to avoid the dreaded never-ending loading indicator. So, if the client script loads after the DOM event has already fired, the client is never notified that it is allowed to start making requests.

Thankfully, the designers of WebSync (that's us!) put some thought into this problem, and had a solution already waiting in the wings:

$(function(){
$.getScript("/client.ashx", function(){
fm.utilities.ready();
});
});

That handy extra line tells the WebSync client that the DOM is ready to be used. It then fires any events that were queued up in the addOnLoad() utility function, running them immediately. That's it! So what're you waiting for - get coding!

Websync Free Trial

Topics:WebSync

Frozen Mountain Software

Started in 2008 and having grown to over 300 customers in 47 countries worldwide, Frozen Mountain provides cross-platform, licensed Real Time Communication (RTC) SDKs and RTC services that allow your organization to incorporate WebRTC audio/video streaming and mixing, selective forwarding, call signalling and much more into your applications.

Welcome! Grab a Coffee and Enjoy!

Thought provoking insights, ideas, and news tailored for WebRTC professionals,  live streaming junkies, and generally anyone considering adopting real-time video capabilities into their business.

Subscribe to Us