When doing web development, we often modify the hosts file for testing, but occasionally we find that changing the hosts file does not take effect immediately. This is due to the fact that the browser itself caches the DNS (domain name pointing). In addition to caching, since HTTP 1.1 supports connection reuse, if the page was previously opened, then even if the DNS cache is cleared, the connection will continue to connect to the old domain pointing address again due to reuse. If the connection is multiplexed it will be necessary to manually close the active connection.
View the actual connection address
Viewing the actual connection address can be done through the network panel of the development tool.
Clear cache method
- Type in the address bar:
chrome://net-internals
- Under the DNS tab, click "Clear host cache" to clear the cache.
Method to close active connections
- Type in the address bar: chrome://net-internals.
- under the Sockets tab, close active connections.
One more way to clear the macOS DNS cache
sudo dscacheutil -flushcache
sudo killall -HUP mDNSResponder