问题
I am having a single page application running in webpack dev server for hot reloading on my local. However, the backend application of it was not on my local, it was host in a remote server, say http://remote-server.com.
When I use such address in the chrome address field: 0.0.0.0:3000/homepage
, the http request (api calls to remote backend server) was 5 times (even more) slower than using localhost:3000/homepage
I am really confused why would this happen?
Actually, more precisely, the question would be, what does it mean to a browser/server when I ask Chrome to ping 0.0.0.0, given the fact that 0.0.0.0 is simply used to say 'bind to any possible address'
The http requests are like
get /remote-server.com/api/v1/users
get /remote-server.com/api/v1/products
get /remote-server.com/api/v1/prices
I was expecting the http requests takes the same amount of time.. when I use 0.0.0.0
and localhost
回答1:
what does it mean to a browser/server when I ask Chrome to ping 0.0.0.0, given the fact that 0.0.0.0 is simply used to say 'bind to any possible address'?
By specification RFC5735, 0.0.0.0
only represents "source addresses", which means it is a non-routable address and cannot be used for destination.
However, for practical reason, many client software treat 0.0.0.0
as localhost
. Such software list includes: Chrome, Firefox, Safari, curl, telnet etc. Because, as many web server software launch with messages like "listen on 0.0.0.0...", allow visiting to 0.0.0.0
is very user-friendly for junior developers.
Actually, for Chrome, this behavior was discussed as an issue, the issue's status was "WontFix" at the beginning, but later changed to "Fixed" with following solution:
Allow explicit navigations to "0.0.0.0" to support systems where this performs a navigation to localhost (in defiance of specs... but seemingly common).
This still prevents navigation to any other IP with leading octet 0, and only allows 0.0.0.0 when it's actually entered in 4-component dotted-quad form.
来源:https://stackoverflow.com/questions/55565334/what-does-chrome-server-do-when-i-use-0-0-0-0-instead-of-localhost-in-browser