Socket.io script size reduce

2019-02-24 22:54发布

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?

4条回答
混吃等死
2楼-- · 2019-02-24 23:31

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.

查看更多
SAY GOODBYE
3楼-- · 2019-02-24 23:36

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楼-- · 2019-02-24 23:39

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.

查看更多
劫难
5楼-- · 2019-02-24 23:51

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.

查看更多
登录 后发表回答