Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is XHR and htmlfile preferred to JSONP?

Tags:

socket.io

I'm using socket.io with Node.js. Everything works fine with websockets, but I have to support older clients like IE6 and similar. I had a lot of trouble using XHR (does not work at all on IE6) and htmlfile (sending from server works, but sending from client only works for first message). Getting desperate, I switched to JSONP and everything works great.

Looking at socket.io documentation, the recommended order is:

io.set('transports', [
    'websocket'
  , 'flashsocket'
  , 'htmlfile'
  , 'xhr-polling'
  , 'jsonp-polling'
]);

Why is this recommended, when JSONP seems to be more reliable than htmlfile and xhr-polling?

like image 795
Milan Babuškov Avatar asked Dec 04 '25 16:12

Milan Babuškov


1 Answers

Here's what I discovered:

JSONP produces ugly flashes on the screen with Firefox and does not work nice with Opera. So, XHR is better for older Firefox versions and for Opera.

The best solution seems to be configuring the transports on the client after detecting the browser and version.

like image 50
Milan Babuškov Avatar answered Dec 07 '25 17:12

Milan Babuškov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!