2

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

Rudy Hinojosa
  • 1,448
  • 14
  • 15
  • Which means the script wasn't loaded successfully. Also make sure you are actually using two separate script elements to load the library and for your code. – Felix Kling Apr 28 '14 at 16:02
  • Thank you Felix, I originally had placed two script tags but I was still getting the same error. Thank you for your fast responses. – Rudy Hinojosa Apr 28 '14 at 16:07
  • Is ` tag. – Amy Apr 28 '14 at 16:08
  • It was bad formatting on my part. I've revised the code as is now. Thank you. But still getting the error. I'm using Visual Studio 2013, MVC4 Mobile Application. – Rudy Hinojosa Apr 28 '14 at 16:09
  • you can use [this](https://github.com/h5bp/html5-boilerplate/blob/master/index.html#L24-L25) snippet from the HTML5 boilerplate to prevent this error in the future. – agconti Apr 28 '14 at 16:56
  • @agconti - I was momentarily excited about this, but alas, I believe this process only suppressed the invalid character message but still produced this: http://screencast.com/t/dIbxFvzOZDp – Rudy Hinojosa Apr 28 '14 at 17:05
  • @RudyHinojosa all that snippet does it that it checks if you script loaded successfully from a CDN an then if not, loads it from your server – agconti Apr 28 '14 at 17:11
  • @agconti Thank you good people. I think this is going to ultimately be an issue with the script. The line itself that inits the script for platform.min.js instantly fails. No matter where I call it from. I don't know if Visual Studio 2013 is having some type of internal conflict with the call to this script, or if this problem is global. If I find an answer, I will be sure to update everyone. Thank you again for your time. – Rudy Hinojosa Apr 28 '14 at 17:24
  • @agconti Problem solved! Going on agconti's hunch, I downloaded the platform.min.js to my own local script. I referenced the file within from my Scripts directory and everything started working. – Rudy Hinojosa Apr 28 '14 at 18:01
  • @RudyHinojosa updated with an answer for future people reading this thread. Please update it as you need. – agconti Apr 28 '14 at 18:27
  • @RudyHinojosa Hi, I'm from GoInstant and I'm looking for information as to why the CDN is/was failing. It looks like maybe the script is getting truncated. Do you have any details (besides the screenshot) from visual studio about how it failed to download completely? – stash Apr 28 '14 at 21:25

2 Answers2

1

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>
agconti
  • 17,780
  • 15
  • 80
  • 114
0

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.

stash
  • 176
  • 2