Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How could I get access to socket.io.min.js in express?

I can connect socket.io through this url: localhost/socket.io/socket.io.js But I need minified version! localhost/socket.io/socket.io.MIN.js is not works.

like image 941
Beast Winterwolf Avatar asked Nov 12 '12 12:11

Beast Winterwolf


People also ask

How do I run a Socket.IO in node JS?

In order to do it, you need to create an index. js file and install socket.io and express. You can use the following command: touch index. js && npm install express socket.io && npm install --save-dev nodemon .


2 Answers

Socket.IO intercepts requests to /socket.io to serve the files it needs. It normally serves them from:

./node_modules/socket.io/node_modules/socket.io-client/dist

However, as said in Socket.IO's wiki, you can serve the files yourself if you prefer.

The files you need are in the /dist folder in the socket.io-client repo.

If you want to force production settings all the time, you can just add this to your node app right before calling listen():

io.enable('browser client minification');  // send minified client
io.enable('browser client etag');          // apply etag caching logic based on version number
io.enable('browser client gzip');          // gzip the file
io.set('log level', 1);                    // reduce logging
io.set('transports', [                     // enable all transports (optional if you want flashsocket)
    'websocket'
  , 'flashsocket'
  , 'htmlfile'
  , 'xhr-polling'
  , 'jsonp-polling'
]);
like image 68
Laurent Perrin Avatar answered Oct 21 '22 07:10

Laurent Perrin


Latest socket.io.js minified version here, as of today (version 0.9.16):

http://cdnjs.cloudflare.com/ajax/libs/socket.io/0.9.16/socket.io.min.js

like image 34
AmpT Avatar answered Oct 21 '22 08:10

AmpT