JavaScript runtime error: 'goinstant' is undefined

254 Views Asked by At

I'm new at goinstant. I'm following the example and get the following error at runtime.

JavaScript runtime error: 'goinstant' is undefined

here is the code:

<script src="https://cdn.goinstant.net/v1/platform.min.js"></script>
<script>
var url = "https://goinstant.net/xxxxxxx/test";
var connect = goinstant.connect(url);
connect.then(function (result) {
    var conn = result.connection;
    var lobby = result.rooms[0];
    alert(lobby);
});
</script>

Am I missing Something? I should caveat this by saying I got an error before this one regarding the platform.min.js . The error is:

JavaScript critical error at line 1, column 1 in https://cdn.goinstant.net/v1/platform.min.js\n\nSCRIPT1014: Invalid character

2

There are 2 best solutions below

0
agconti On BEST ANSWER

The issue is that the CDN is not serving your script correctly.

Use this trick from the HTML5 Boilerplate to create a fall back to a local copy for when this happens:

<script src="https://cdn.goinstant.net/v1/platform.min.js"></script>
<script>window.goinstant || document.write('<script src="js/vendor/platform.min.js"><\/script>')</script>
0
stash On

I'm looking into why the GoInstant CDN is failing, but I thought I'd suggest another way to fix it in the interim.

http://www.hanselman.com/blog/CDNsFailButYourScriptsDontHaveToFallbackFromCDNToLocalJQuery.aspx details another way to do this auto-magically in ASP.net. Scroll down to where you see "Fire up Visual Studio 2012 and make a new ASP.NET 4.5 Web Forms application" and there's a quite long explanation of how to do it. Ultimately, this outputs a script-src-with-fallback set of tags similar to the one in @agconti's answer.