Skip to main content
Version: 4.x

Client Installation

Version compatibility​

Here is the compatibility table between the server and the JS client:

JS Client versionSocket.IO server version
1.x2.x3.x4.x
1.xYESNONONO
2.xNOYESYES1YES1
3.xNONOYESYES
4.xNONOYESYES

[1] Yes, with allowEIO3: true

Please check the associated migration guides:

Browser support​

Socket.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:

Browser support

Latest releases​

Installation​

Standalone build​

By 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 CDN​

You can also include the client bundle from a CDN:

<script src="https://cdn.socket.io/4.6.0/socket.io.min.js" integrity="sha384-c79GN5VsunZvi+Q/WObgk2in0CbZsHnjEqvFxC5DxHn9lTfNce2WW6h2pH6u/kF+" crossorigin="anonymous"></script>

Socket.IO is also available from other CDN:

There are several bundles available:

NameSizeDescription
socket.io.js34.7 kB gzipUnminified version, with debug
socket.io.min.js14.7 kB min+gzipProduction version, without debug
socket.io.msgpack.min.js15.3 kB min+gzipProduction 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 NPM​

The Socket.IO client is compatible with bundlers like webpack or browserify.

npm install 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 tree​

A basic installation of the client includes 9 packages:

└─┬ socket.io-client@4.6.0
β”œβ”€β”€ @socket.io/component-emitter@3.1.0
β”œβ”€β”¬ debug@4.3.4
β”‚ └── ms@2.1.2
β”œβ”€β”¬ engine.io-client@6.4.0
β”‚ β”œβ”€β”€ @socket.io/component-emitter@3.1.0 deduped
β”‚ β”œβ”€β”€ debug@4.3.4 deduped
β”‚ β”œβ”€β”€ engine.io-parser@5.0.6
β”‚ β”œβ”€β”¬ ws@8.11.0
β”‚ β”‚ β”œβ”€β”€ UNMET OPTIONAL DEPENDENCY bufferutil@^4.0.1
β”‚ β”‚ └── UNMET OPTIONAL DEPENDENCY utf-8-validate@^5.0.2
β”‚ └── xmlhttprequest-ssl@2.0.0
└─┬ socket.io-parser@4.2.2
β”œβ”€β”€ @socket.io/component-emitter@3.1.0 deduped
└── debug@4.3.4 deduped

Transitive versions​

The 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 versionengine.io-client versionws version1
4.6.x6.4.x8.11.x
4.5.x6.2.x8.2.x
4.4.x6.1.x8.2.x
4.3.x6.0.x8.2.x
4.2.x5.2.x7.4.x
4.1.x5.1.x7.4.x
4.0.x5.0.x7.4.x
3.1.x4.1.x7.4.x
3.0.x4.0.x7.4.x
2.5.x3.6.x7.4.x
2.4.x3.5.x7.4.x

[1] for Node.js users only. In the browser, the native WebSocket API is used.