Search code examples
google-chromehttptcp

Why is my own webserver is slow with Chrome, fast with Firefox? "Initial connection" for every request ~300ms


To learn about HTTP and to solve a problem I have, I wrote my own web server for internal use.

I noticed that Chrome is significantly slower than Firefox or my mobile browser. It turns out that Chrome takes 300 ms per request's "initial connection" and Firefox does not, for almost every request, consistently.

FWIW, I implemented this with Python sockets, with timeouts, and multiple persistent threads.

Now don't kill me for this, but I haven't implemented Connection: keep-alive. I feel that if this is fast in Firefox, it can be fast in Chrome. Chrome is doing something weird with the connection and I don't know how to remove this delay. Googling this problem is very difficult because nobody uses this exact wording or means the same thing.

Chrome:

Chrome

Firefox:

FireFox


Solution

  • Solved, O-M-G. In Chrome, if I write my address:

    http://127.0.0.1/
    

    it's fast!

    If I write my address:

    http://localhost/
    

    it's slow. This does not affect Firefox.