Chrome slow when loading local virtual host

google-chromehostsmamp

I'm developing a local website with MAMP. I've configured a virtual host (hosts files, and apache vhosts).

/etc/hosts file:

127.0.0.1   domain.com

MAMP Vhosts config

<VirtualHost *:80>
    DocumentRoot "/route/to/folder"
    ServerName domain.com
</VirtualHost>

It all works fine, but in Chrome sometimes the local website takes a few seconds to load, when it should load instantly. I've narrowed down the problem to Chrome as it works fine 100% of the time with Safari.

When this happens in Chrome, the status bar at the bottom says "resolving host". It would seem like it's waiting for a DNS server to respond… but isn't the hosts file overriding any DNS calls?

Any ideas what might be happening?

Best Answer

The solution was to move the domain in the /etc/hosts file to the same entry as localhost.

127.0.0.1   localhost domain.com

See this StackOverflow thread.