Slow loading of the Socket.IO client library

enter image description here

I start my server and refresh the page in the browser, and then it takes> 2s to load the JS resource. If I reload the page in any browser, it loads quickly.

This only happens on the first request after starting the server. I believe this is due to the fact that it first collects the JS file, and then after that it is cached on the server.

Is there anything you can do to reduce this time?

I tried both with production settings and without them (gzip, minify, etc.).

Client Code:

<script src="/socket.io/socket.io.js"></script> <script> var socket = io.connect(); </script> 

Server Code:

 var express = require('express'), expressServer = express.createServer(), socketServer = require('socket.io').listen(expressServer); expressServer.listen(1337); 
+7
source share
2 answers

There is currently an error in socket.io that causes this. Make sure you do NOT have this set installed and it should load MUCH faster:

 io.set('browser client gzip', true); // gzip the file 

The first call to load socket.io.js will try to compress it and store it in memory. You will encounter these errors:

You can increase the speed using the mini version and enable caching until it is fixed:

 io.set('browser client minification', true); // send minified client io.set('browser client etag', true); // apply etag caching logic based on version number 
+3
source

Somehow, your jQuery library, which is more than half the size of the socket.io library, loads 50 times faster. Could it have been cached before? Ultimately, the browser simply downloads the file.

In any case, this guy claims to have cut it.

0
source

All Articles