Client Installation
#
Version compatibilityHere is the compatibility table between the server and the JS client:
JS Client version | Socket.IO server version | |||
---|---|---|---|---|
1.x | 2.x | 3.x | 4.x | |
1.x | YES | NO | NO | NO |
2.x | NO | YES | YES1 | YES1 |
3.x | NO | NO | YES | YES |
4.x | NO | NO | YES | YES |
[1] Yes, with allowEIO3: true
Please check the associated migration guides:
#
Browser supportSocket.IO does support IE9 and above. IE 6/7/8 are not supported anymore.
Browser compatibility is tested thanks to the awesome Sauce Labs platform:
#
Latest releases- 4.4.1 (2022-01-06): GitHub release / diff / npm
- 4.4.0 (2021-11-18): GitHub release / diff / npm
- 4.3.2 (2021-11-08): GitHub release / diff / npm
- 4.3.1 (2021-10-17): GitHub release / diff / npm
- 4.3.0 (2021-10-15): GitHub release / diff / npm
- 4.2.0 (2021-08-30): GitHub release / diff / npm
#
Installation#
Standalone buildBy default, the Socket.IO server exposes a client bundle at /socket.io/socket.io.js
.
io
will be registered as a global variable:
<script src="/socket.io/socket.io.js"></script><script> const socket = io();</script>
If you don't need this (see other options below), you can disable the functionality on the server side:
const { Server } = require("socket.io");
const io = new Server({ serveClient: false});
#
From a CDNYou can also include the client bundle from a CDN:
<script src="https://cdn.socket.io/4.4.1/socket.io.min.js" integrity="sha384-fKnu0iswBIqkjxrhQCTZ7qlLHOFEgNkRmK2vaO/LbTZSXdJfAu6ewRBdwHPhBo/H" crossorigin="anonymous"></script>
Socket.IO is also available from other CDN:
- cdnjs: https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.4.1/socket.io.min.js
- jsDelivr: https://cdn.jsdelivr.net/npm/socket.io-client@4.4.1/dist/socket.io.min.js
- unpkg: https://unpkg.com/socket.io-client@4.4.1/dist/socket.io.min.js
There are several bundles available:
Name | Size | Description |
---|---|---|
socket.io.js | 34.7 kB gzip | Unminified version, with debug |
socket.io.min.js | 14.7 kB min+gzip | Production version, without debug |
socket.io.msgpack.min.js | 15.3 kB min+gzip | Production version, without debug and with the msgpack parser |
The debug package allows to print debug information to the console. You can find more information here.
During development, we recommend using the socket.io.js
bundle. By setting localStorage.debug = 'socket.io-client:socket'
, any event received by the client will be printed to the console.
For production, please use the socket.io.min.js
bundle, which is an optimized build excluding the debug package.
#
From NPMThe Socket.IO client is compatible with bundlers like webpack or browserify.
- NPM
- Yarn
- pnpm
npm install socket.io-client
yarn add socket.io-client
pnpm add socket.io-client
The client can also be run from Node.js.
Note: for the reasons cited above, you may want to exclude debug from your browser bundle. With webpack, you can use webpack-remove-debug.
Note for TypeScript users: the types are now included in the socket.io-client
package and thus the types from @types/socket.io-client
are not needed anymore and may in fact cause errors:
Object literal may only specify known properties, and 'extraHeaders' does not exist in type 'ConnectOpts'
#
Miscellaneous#
Dependency treeA basic installation of the client includes 15 packages:
โโโฌ socket.io-client@4.4.1 https://github.com/socketio/socket.io-client โโโ @socket.io/component-emitter@3.0.0 โโโ backo2@1.0.2 โโโฌ debug@4.3.3 โ โโโ ms@2.1.2 โโโฌ engine.io-client@6.1.1 โ โโโ @socket.io/component-emitter@3.0.0 deduped โ โโโ debug@4.3.3 deduped โ โโโฌ engine.io-parser@5.0.2 โ โ โโโ base64-arraybuffer@1.0.1 โ โโโ has-cors@1.1.0 โ โโโ parseqs@0.0.6 โ โโโ parseuri@0.0.6 deduped โ โโโฌ ws@8.2.3 โ โ โโโ UNMET OPTIONAL DEPENDENCY bufferutil@^4.0.1 โ โ โโโ UNMET OPTIONAL DEPENDENCY utf-8-validate@^5.0.2 โ โโโ xmlhttprequest-ssl@2.0.0 โ โโโ yeast@0.1.2 โโโ parseuri@0.0.6 โโโฌ socket.io-parser@4.1.1 โโโ @socket.io/component-emitter@3.0.0 deduped โโโ debug@4.3.3 deduped
#
Transitive versionsThe engine.io-client
package brings the engine that is responsible for managing the low-level connections (HTTP long-polling or WebSocket). See also: How it works
socket.io-client version | engine.io-client version | ws version1 |
---|---|---|
4.4.x | 6.1.x | 8.2.x |
4.3.x | 6.0.x | 8.2.x |
4.2.x | 5.2.x | 7.4.x |
4.1.x | 5.1.x | 7.4.x |
4.0.x | 5.0.x | 7.4.x |
3.1.x | 4.1.x | 7.4.x |
3.0.x | 4.0.x | 7.4.x |
2.4.x | 3.5.x | 7.4.x |
[1] for Node.js users only. In the browser, the native WebSocket API is used.