3

socket.io source script goes like 70k, a great part is comments, spaces...

I need to reduce that script to a smaller size Some scripts do not even have spaces and the code is all toghether, this reduces the script original size.

Where is the location of the socket.io script so that I can remove comments and spaces? Or is there a socket.io allready whithout comments and spaces with a smaller size?

forsvarir
  • 10,749
  • 6
  • 46
  • 77
Vitor
  • 191
  • 4
  • 10

4 Answers4

10

There is a setting in the socket.io configuration for this:

https://github.com/LearnBoost/Socket.IO/wiki/Configuring-Socket.IO

browser client minification defaults to false

Does Socket.IO need to send a minified build of socket.io.js.

You may also enable gzip compression on the library.

LeChuck
  • 226
  • 2
  • 5
  • 1
    For NodeJS at least, this is the only correct answer. When SocketIO is used in a node app, it automatically servers the client script on a preset url. You can set a number of properties, such as minification, for this feature as above. – mtsr Jan 26 '12 at 08:15
  • Also if you want Cache-Control/Max-age to apply, then request specific version E.g. `src='/socket.io/socket.io.v0.9.16.js'` – ankitjaininfo Feb 13 '14 at 10:42
4

The client .js file is in *yourdir*/node_modules/socket.io/node_modules/socket.io-client/dist

There is one file called socket.io.min.js which is minified already.

Tor Valamo
  • 33,261
  • 11
  • 73
  • 81
  • Hi tanks for your quick help, I found that minified file, i've renamed socket.io.min.js to socket.io.js and removed the non minified file, but in browser I keep getting the normal scipt and not minified :/ Anything wrong? Tanks – Vitor Jan 26 '12 at 01:33
  • Are you editing in the correct directory? If you installed it with npm, you will have one global directory `/usr/local/lib/node_modules...` and possibly one local directory `yourproject/node_modules...`. – Tor Valamo Jan 26 '12 at 02:08
  • I think you should clear your browser cache to retrieve minified version. – Alfred Jan 26 '12 at 09:37
2

The OP fixed the problem by going to /node_modules/socket.io/lib and editing 'manager.js', to set both "minification" and "gzip compression" to "true". They had to do this way because because they were using nowJS which indirectly uses 'socket.io'

This reduced the file from 70k to about 4k!

forsvarir
  • 10,749
  • 6
  • 46
  • 77
1

it seems socket.io is either returning some other file or returning by building at run time. I replaced socket.io.js by renaming the min one. cleared cache of browser but still getting the old file.

  • I don't know who gave you the "drive-by downvote", but I also suspect that you may be correct. My reasoning is that the file retrieved by Chromium is ~70kb, yet the file in the socket.io-client/dist/ folder is ~ 101kb. The minified version, however, is ~45kb. So I really don't know what's going on. – snapfractalpop Nov 11 '12 at 02:02