I quite enjoyed this poll because the results were so neck and neck. It was only in the last week or so that a clear winner has emerged.
Like all polls ever run in the history of this website, there is lots of things to consider and the poll was probably too simple for it's own good. Nonetheless, I consider just getting people thinking about this issue a success. At the very surface: 20k is smaller but the CDN is faster and more likely to be cached.
There is a bunch more too it though...
- The CDN is probably a different domain, so even if a user does need to load the file it doesn't count against the maximum concurrent connections for a single domain.
- Loading the JS is one thing, but executing the JS is another. Executing 200k of JS will always be slower than 20k.
- Da_n reminds us they aren't mutually exclusive. You could attempt to load from the CDN and fall back to local.
- Evert reminds us that some IP address/ranges can be blocked in some countries, so the more different ones we pull from the higher the chances that some resources will be block and lead to problems loading the page.
- In the case of the Google CDN (the most popular for this sort of thing), the only way the caching is in place is if you link to a very specific version of a library, like 1.8.14. If you link any less specifically (e.g. 1.8 will give you the latest version that is 1.8.something) it's not cached (or not cached very long).
- CDN saves bandwidth, and those costs can be significant (e.g. The 100k image sprite on the current design of this site used 50+ GB of bandwidth in the last 30 days. That's one file.).
- Locally, you have the option to merge the 20k into other JS files and load a single resource instead of many.
- Paul Irish says we should A/B test for speed and pick the fastest.
- Mobile is a very serious consideration. Mobile browsers have far less room for cache and (sometimes) have less bandwidth.
- Kent Davidson reminds us that if we are super worried about privacy, the CDN may be out, as it gives referrer strings to the CDN for each person requesting the file.
- Hosting that small custom file on your own CDN has big advantages. It may not have any chance of being cached coming in, but has the other advantages.
There was another good point brought up in the comments by Jayphen:
Posts like this make me worry about the kind of misinformation spread by these kinds of polls…
If the majority of other developers do the wrong thing, that doesn’t make it right.
Just because "local" won this poll, doesn't make it the right answer all the time (see considerations above).
New poll soonish. If you have an idea for a poll on CSS-Tricks, leave it as a comment below. I'd like to refill the reserves of poll ideas.