I'm not sure what's considered 'best practice' here, but I would point out that there are advantages to hosting the file yourself:
- You don't have to worry about the file disappearing from the remote site
- You provide a small measure of privacy to your users
- You can specify a caching policy on your server
- Basically, more control overall.
- a single visitor may see a more streamlined loading performance if your server is configured to keep the socket open long enough for a user to request all files in one socket connection - (see "keep-alive" setting)
The disadvantages are:
- You are consuming bandwidth on your site, which you may get charged for
- I'd guess that code.jquery.com is hosted from servers configured as a Content Delivery Network (CDN) which might feel more reponsive, depending on a million little things.
- Whoever is hosting the JS file for you has some idea of your user traffic -- you are trading a little bit of your privacy and your users' privacy for their hosting services
- If the Jquery file gets patched without changing the JS file name, your users will seamlessly download the new version
You might consider making two versions of your page and testing their performance. You can use the dev tools in Chrome or Firefox to check the timing of page loads.
Your question is a tricky one, and would depend on a lot of factors. My point about keep-alive is that browsers work by opening a socket connection across the internet to the server. The socket opening operation is subject to network latency, and there may be a queue on the remote server and you may have to wait for a free process to handle your socket opening request.
Once the socket connection opens, you request the first url -- the url of your over all page. E.g., https://example.com/file.html. The remote server will cough up file.html and, if conditions are right, your browser will parse that file and identify additional resources it might need to request: JS files, CSS files, image files, etc. If the keep-alive configuration is set right, these additional files are identified before the socket connection closes and you can simply request all the additional files immediately, without having to make another socket open request, waiting for the socket to open, etc.