Minify / socket.io / socket.io.js since 1.0

Today released 1.0 from socket.io. I just updated, and now the following does not work:

io.enable('browser client minification'); io.enable('browser client etag'); io.enable('browser client gzip'); 

The new documentation seems to be incomplete, how to minimize and enable gzip + etag with 1.0?

+6
source share
4 answers

This seems to be impossible in 1.0 - a recursive search in the socket.io folder with the words "gzip", "etag" and "minif" does not produce any relevant results. In addition, in previous versions there was a socket.io.min.js file next to socket.io.js . Now he is absent.

Perhaps the following solution does not satisfy, but if you use nginx (or another web server) in front of node, you can serve socket.io.js (manually compressed by Google Closure Compiler , for example) with your own. You can enable gzip and etag on nginx.

+7
source

Check this out: http://socket.io/blog/introducing-socket-io-1-0/

CDN Delivery

One of the best decisions that we made at an early stage was that implementing the Socket.IO server would not only give you access to the real-time protocol, but Socket.IO itself would also serve the client.

Generally, all you have to do is include this snippet:

<script src="/socket.io/socket.io.js"></script>

If you want to optimize access to the client by serving it next to your users, ensure the maximum level of gzip compression (thanks to Googles zopfli and proper caching support, you can now use our CDN. Its free, forever and has built-in SSL support:

<script src="https://cdn.socket.io/socket.io-1.0.0.js"></script>

Also, if you go from 0.9: http://socket.io/docs/migrating-from-0-9/

+5
source

About compression:

Looking at the old code for version 0.9 , it seems that it creates gzip processes for compression. I can not find any caching and .

We did not notice a significant slowdown in production because of this, so maybe at some point he does something smart, but I'm not surprised that they deleted all this code.

Minimization was using uglify before :

The sample from https://cdn.socket.io/socket.io-1.0.0.js is 78.5 kB, the shortened version is 57.1 kB. 37% more, but not significantly, when you compare it with the amount of data that will be transmitted through it.

+2
source

I used a CDN, but I had problems with a cross-origin domain with firefox.

Actually this problem arises because socket.io is launched in firefox using the xhr-poll transfer method and immediately switches to websocket, instead chrome starts directly from websocket. By setting websocket as the first transport method (according to the js client configuration), the problem has been fixed, but what about clients that do not yet support websocket? So I went back to the node serverd version.

+1
source

Source: https://habr.com/ru/post/970150/


All Articles