Socket.io Hardcoded Vs Dynamic Connection Url
Why most tutorials, examples and questions here use the local IP or localhost (or any other hard-coded path) like this: var socket = io.connect('http://127.0.0.1:3700'); Instead o
Solution 1:
I don't see any risks involved, if you have a dynamic connection url instead of a hard-coded one.
In my opinion a hard-coded url like in your first example is more easier for beginners to understand. The second example could be confusing. (Actually I also had to check, if document.location.host contains the port number or not). And that's why most examples and tutorials use the hard-coded variant, I guess.
If the third example works in both your development and production environment, you should use it. But in cases where the socket is running on a different port and/or host than the rest of the application, it does not work and it is necessary to hard-code it somewhere in the script.
Post a Comment for "Socket.io Hardcoded Vs Dynamic Connection Url"