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
Ruby Equivalent to JavaScript's Encodeuricomponent That Produces Identical Output
Why Does "True" == True Show False in JavaScript
How to Run JavaScript Inside Swift Code
How to Run Node Js Code from Npm Inside of Swift
How to Get Objects Value If Its Name Contains Dots
Stop a Youtube Video with Jquery
How to Save HTML Page as PDF Using JavaScript or Jquery
What Are "Top Level JSON Arrays" and Why Are They a Security Risk
How to Pause Setinterval() Functions
Use Browser Search (Ctrl+F) Through a Button in Website
Uncaught Referenceerror: Reactdom Is Not Defined
Has Anyone Else Run into Problems Styling Twitter Typeahead's Searchbar
How to Prevent Closing Browser Window
How to Call an Async Function Inside a Useeffect() in React
Jquery Beforeunload When Closing (Not Leaving) the Page
How to Split Comma Separated String Using JavaScript
Retrieve Dom Target from Drag Callback When 'This' Is Not Available
Browser-Independent Way to Detect When Image Has Been Loaded