Skip to content

Loading…

Inserting callback in DOM before inserting script in JSONP handshake. #530

Closed
wants to merge 3 commits into from

4 participants

@gabmontes

There are some old clients that, like the BlackBerry OS 5 browser, that synchronously handle the request, insertion and execution of 'script' tags into the DOM. This behavior breaks the JSONP handshake because the 'script' tag is requested, inserted into the DOM and executed before the callback is set. In current implementations, this is done asynchronously and the callback is set before the JSONP request returns, so it works fine.

In this proposed change, the callback is first set and then the JSONP call is made, ensuring the callback exists even for weird/old browser implementations with no expected changes in actual performance.

@lxspine

I have the same problem on using socket.io-client with Dojo. This change solves the problem. Thank you!

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 9, 2012
  1. @adityab
Commits on Nov 10, 2012
  1. @rauchg

    Merge pull request #491 from adityab/amd-unsupport

    rauchg committed
    Don't try to support AMD loaders in socket.io
Commits on Jan 19, 2013
This page is out of date. Refresh to see the latest.
Showing with 5 additions and 7 deletions.
  1. +2 −4 bin/builder.js
  2. +3 −3 lib/socket.js
View
6 bin/builder.js
@@ -85,15 +85,13 @@ var baseTransports = {
/**
* Wrappers for client-side usage.
- * This enables usage in top-level browser window, client-side CommonJS systems and AMD loaders.
+ * This enables usage in top-level browser window and client-side CommonJS systems.
* If doing a node build for server-side client, this wrapper is NOT included.
* @api private
*/
var wrapperPre = "\nvar io = ('undefined' === typeof module ? {} : module.exports);\n(function() {\n";
-var wrapperPost = "\nif (typeof define === \"function\" && define.amd) {" +
- "\n define([], function () { return io; });" +
- "\n}\n})();";
+var wrapperPost = "\n})();";
/**
View
6 lib/socket.js
@@ -138,13 +138,13 @@
var insertAt = document.getElementsByTagName('script')[0]
, script = document.createElement('script');
- script.src = url + '&jsonp=' + io.j.length;
- insertAt.parentNode.insertBefore(script, insertAt);
-
io.j.push(function (data) {
complete(data);
script.parentNode.removeChild(script);
});
+
+ script.src = url + '&jsonp=' + (io.j.length - 1);
+ insertAt.parentNode.insertBefore(script, insertAt);
} else {
var xhr = io.util.request();
Something went wrong with that request. Please try again.