Socket.io script size reduce

2019-02-24 23:35发布

问题:

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?

回答1:

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.



回答2:

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.



回答3:

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!



回答4:

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.