“不赞成在主线程上使用同步XMLHttpRequest".使用nodejs app.get或http服务器 [英] "Synchronous XMLHttpRequest on the main thread is deprecated" using nodejs app.get or http-server

查看:182
本文介绍了“不赞成在主线程上使用同步XMLHttpRequest".使用nodejs app.get或http服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在AngularJS中创建一个前端,用于node.js中的一个后端.我可以选择两个简单的node.js前端服务器来服务前端网页:一个是简单的app.get in express,另一个是使用http-server软件包.

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.

无论使用哪种前端服务器代码,我都会在Chrome中收到以下浏览器控制台消息:

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

不赞成在主线程上使用同步XMLHttpRequest,因为它会对最终用户的体验产生不利影响.要获取更多帮助,请检查 http://xhr.spec.whatwg.org/.

为确保这不是由Angular(或Bootstrap)引起的,我将网页缩减为以下内容:

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>

为什么会收到错误消息? http服务器是否总是会导致此错误?如何使用nodejs设置前端服务器,以免发生此错误(只是这个简单的"hello world"页面将是起点)?

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)?

我用来替代http-server的服务器代码是:

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);

另一个奇怪的地方.从http-server控制台看来,http-server正在提供两个资源:/index.html符合预期,还有/favicon.ico-这很奇怪,因为在任何地方都没有提到.

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.

最后一个奇怪的地方:这仅在Chrome中发生.从IE出发没有问题,也不需要favicon.ico.

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

在Chrome中,我清除了所有浏览数据,但自动填充表单数据,密码和内容许可除外.

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

推荐答案

感谢您的评论.我已经找到了问题所在,而且它在Chrome中-尤其是扩展程序中.

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

问题出在我拥有的扩展程序上:PropertyWizza v2.0.禁用此扩展名可以解决此问题.现在,我将其卸载,以免干扰我的开发消息.

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.

所有这些都是推论的,因为我注意到只要我使用Chrome,从家里的任何计算机访问任何网站(例如,包括BBC和GitHub)时,我都会遇到相同的问题.

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.

这篇关于“不赞成在主线程上使用同步XMLHttpRequest".使用nodejs app.get或http服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆