简体   繁体   English

使用 webpack-dev-server 时,为什么 Chrome 会在每秒请求之前等待?

[英]Why is Chrome waiting before every second request when using webpack-dev-server?

Can someone help me understand what is happening in the hundreds of milliseconds before the initial connection?有人可以帮助我了解初始连接前数百毫秒内发生的事情吗?

It happens on every other request only as shown.它只发生在每个其他请求上,如图所示。

The requests are POSTs made to the same ressource on localhost - against an ASP.NET Core web application.请求是针对 ASP.NET Core Web 应用程序对 localhost 上的相同资源发出的 POST。

I've looked at other similar questions and answers too, but I have seen no examples where there's just nothing before the initial connection.我也看过其他类似的问题和答案,但我没有看到在初始连接之前什么都没有的例子。 Everyone else seems to have a bar of "Stalled" or "Queueing".其他人似乎都有一个“停顿”或“排队”的酒吧。

所有请求的瀑布

单个请求的瀑布

The "short" requests look like this: “短”请求如下所示:

在此处输入图片说明

Chrome version: 74.0.3729.131 (Officiel version) (64-bit) Chrome 版本:74.0.3729.131(官方版本)(64 位)

UPDATE 1 : This does not happen in Microsoft Edge.更新 1 :这在 Microsoft Edge 中不会发生。 Every request is short there.每个请求都很短。 No wait.不用等。

UPDATE 2 : Downloading a HAR file for a long request reveals a very long "connect" time:更新 2 :下载一个长请求的 HAR 文件显示一个很长的“连接”时间:

 "timings": {
  "blocked": 1.135999995024409,
  "dns": 0.0030000000000000027,
  "ssl": -1,
  "connect": 301.202,
  "send": 0.18900000000002137,
  "wait": 79.29900000206612,
  "receive": 3.750999996555038,
  "_blocked_queueing": 0.8449999950244091
},

The short one have a connect time of -1:短的连接时间为 -1:

  "timings": {
      "blocked": 0.9680000060191378,
      "dns": -1,
      "ssl": -1,
      "connect": -1,
      "send": 0.091,
      "wait": 50.74499999642931,
      "receive": 2.582000000984408,
      "_blocked_queueing": 0.8130000060191378
    },

But why?但为什么?

UPDATE 3 : Turns out that this only happens when proxying through webpack-dev-server.更新 3 :事实证明,这只发生在通过 webpack-dev-server 代理时。 I'll add that tag too.我也会添加那个标签。 Still only happens in Chrome though.尽管如此,它仍然只发生在 Chrome 中。

UPDATE 4 : A summary of what seems to be the case right now, the pattern emerges when using:更新 4 :现在似乎是这种情况的摘要,使用时会出现该模式:

  • Proxy via webpack-dev-server from localhost:3000 -> localhost:3001, not when going directly to the endpoint at localhost:3001通过 webpack-dev-server 从 localhost:3000 -> localhost:3001 代理,而不是直接进入 localhost:3001 的端点时
  • locahost:3000 as the address in Chrome, not when using 127.0.0.1:3000. locahost:3000 作为 Chrome 中的地址,而不是使用 127.0.0.1:3000 时。
  • Chrome (multiple version including 74.0.3729.131), not Microsoft Edge Chrome(多个版本,包括 74.0.3729.131),而不是 Microsoft Edge
  • Windows 10, not Ubuntu 19.04 Windows 10,而不是 Ubuntu 19.04

Both in NodeJS 10 and NodeJS 12. Tested on multiple machines and with Chrome in incognito mode as well.均在 NodeJS 10 和 NodeJS 12 中。在多台机器上进行了测试,并在隐身模式下使用 Chrome。

I posted this as an issue here https://github.com/webpack/webpack-dev-server/issues/1850 and a solution was found.我将其作为问题发布在这里https://github.com/webpack/webpack-dev-server/issues/1850并找到了解决方案。

Details can be found in the issue discussion, but the solution was to listen directly on IPv6 loopback address instead, like:可以在问题讨论中找到详细信息,但解决方案是直接侦听 IPv6 环回地址,例如:

const server = new WebpackDevServer(webpack(config), {
  hot: true,
  writeToDisk: false,
  historyApiFallback: true,
  contentBase: path.join(__dirname, 'src'),
  proxy: [{
    context: ["/api/**"],
    target: "http://localhost:5000",
    logLevel: 'debug'
  }]
});

// Listen on ::1, details here https://github.com/webpack/webpack-dev-server/issues/1850
server.listen(3000, '::1', err => {
  if (err) {
    return console.log(err);
  }

  console.log('Listening at http://localhost:3000/');
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 React Chrome Tab扩展无法与WebPack Dev Server一起使用 - React Chrome Tab Extension Not Working with WebPack Dev Server 如何从Chrome手动断开Webpack开发服务器的连接 - How to manually disconnect webpack dev server from chrome 为什么在重新计算 chrome 开发工具中的样式之前评估过 js? - js evaluated before recalculating style in chrome dev tools why? 使用chrome dev工具查找代码中的http请求 - find where in the code an http request was made using chrome dev tools 为什么在Chrome开发工具中检查变量后,变量会发生变化? - Why does a var change when I inspect it in Chrome Dev tools? chrome 开发工具网络请求名称 - chrome dev tools network request name 如果未打开开发工具,则Chrome中的HTTP请求会延迟 - HTTP request delayed in Chrome if dev tools not open 如何在 Chrome Dev Tools 中区分同名的 VueJS + WebPack 模块? - How to distinguish identically named VueJS + WebPack modules in Chrome Dev Tools? 如何在 python/java 中使用 Selenium 访问 Chrome 开发工具网络选项卡的请求或摘要的值? - How to access the values of Chrome's Dev tools Network tab's Request or summary using Selenium in python/java? 使用Chrome开发工具调试发布请求 - Debugging Post Request with Chrome Dev Tools
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM