“Synchronous XMLHttpRequest on the main thread is deprecated” using nodejs app.get or http-server

穿精又带淫゛_ 提交于 2019-12-01 06:02:35

问题


I am creating a front end in AngularJS for a backend in node.js. I have the option of two simple node.js front end servers to serve the front end web page: one is a simple app.get in express, the other is using the http-server package.

Whichever front end server code I use, I get the following browser console message in Chrome:

Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check http://xhr.spec.whatwg.org/.

To make sure that this was not caused by anything Angular (or Bootstrap) I have cut back my webpage to the following:

<!DOCTYPE html>
<html lang="en" >
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>zoneshark</title>
  </head>
  <body>
    <h1>Hello, world!</h1>
  </body>
</html>

Why am I getting the error message? Does http-server always cause this error? How can I set up a front end server using nodejs so that this error does not occur (just this simple "hello world" page would be a starting point)?

The server code I am using as an alternative to http-server is:

var express = require('express');
var app = express();

app.get('/', function(req,res) {
  res.sendFile('./index.html', {root: __dirname});
});

app.get(/^(.+)$/, function(req, res) {
  res.sendFile('./' + req.params[0], {root: __dirname});
});

app.listen(80);

Another oddity. From the http-server console, it looks like http-server is serving two resources: /index.html as expected, but also /favicon.ico - which is odd as this is not mentioned anywhere.

The final oddity: this only happens from Chrome. From IE there is no issue, and no favicon.ico is called for.

In Chrome, I have cleared all browsing data, except autofill form data, passwords and content licences.


回答1:


Thanks for the comments. I have tracked down the issue, and it is within Chrome - more particularly extensions.

The issue is with an extension I have: PropertyWizza v2.0. Disabling this extension clears the problem. I will now uninstall it so it doesn't interfere with my development messages.

This was all deduced because I noticed that I had the same problem when accessing any website - including BBC and GitHub for instance - from any computer in my home, as long as I used Chrome.

My advice to anyone starting to debug front-ends for the first time is to check what errors you get on other websites in all your browsers before you begin. This will provide the "control" for your testing.



来源:https://stackoverflow.com/questions/28531743/synchronous-xmlhttprequest-on-the-main-thread-is-deprecated-using-nodejs-app-g

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!