Preloader Wont Ignore Websocket - Pace Js

Preloader wont ignore websocket - pace js

I tried this one, it worked. :)

Pace.options.ajax.trackWebSockets = false;

How to control the load speed of pace.js?

From the docs, it states that you can set configuration options before you load the file. So, in your html page you would do something like this:

<head>
<title>asdfas</title>
<script>
paceOptions = {
ajax: false, // disabled
document: true, // enabled
eventLag: false, // disabled
elements: {
selectors: ['.my-page']
}
};
</script>
<script src="js/pace.js"></script>

This will then use the page's readyState to create the progress bar.

WebSocket connection failed: Error during WebSocket handshake: Unexpected response code: 400

Problem solved! I just figured out how to solve the issue, but I would still like to know if this is normal behavior or not.

It seems that even though the Websocket connection establishes correctly (indicated by the 101 Switching Protocols request), it still defaults to long-polling. The fix was as simple as adding this option to the Socket.io connection function:

{transports: ['websocket']}

So the code finally looks like this:

const app = express();
const server = http.createServer(app);
var io = require('socket.io')(server);

io.on('connection', function(socket) {
console.log('connected socket!');

socket.on('greet', function(data) {
console.log(data);
socket.emit('respond', { hello: 'Hey, Mr.Client!' });
});
socket.on('disconnect', function() {
console.log('Socket disconnected');
});
});

and on the client:

var socket = io('ws://localhost:3000', {transports: ['websocket']});
socket.on('connect', function () {
console.log('connected!');
socket.emit('greet', { message: 'Hello Mr.Server!' });
});

socket.on('respond', function (data) {
console.log(data);
});

And the messages now appear as frames:

working websockets

This Github issue pointed me in the right direction. Thanks to everyone who helped out!



Related Topics



Leave a reply



Submit