Lately, I've come across many articles which suggest that you host your own static assets (especially fonts and css) instead of using a worldwide CDN like CDNJS. The argument they cite is that your own site will be much faster than CDN, so the assets will load faster.
But my argument is that if I use a popular library like jquery or bootstrap, chances are that they've already been downloaded to the user's local machine through a CDN (because dozens of other websites the user may have visited use CDNs). So, the network cost is zero! But if I host a jquery.min.js or bootstrap.min.css specifically on my server, it'll be an additional toll on network resources, isn't it?
So, I think that hosting your own asset is an anti-pattern, what do you think?
Top comments (4)
Arguments in favor of hosting your own assets:
Arguments in favor of using CDN-hosted assets:
Also, note that both arguments favoring CDN hosting become a bit weaker if you're doing a PWA and your Service Worker is sanely handling the caching.
Apparently it could be a good idea:
How to Self-Host Google Fonts on Your Own Server
Kelli Blalock ・ Feb 19 '19 ・ 5 min read
Possible trade-off: increased risk that your site goes down if the CDN goes down.
Kind of related: You cannot develop your CDN-using site when you're offline.
I found that out when I was on a 10-hour flight. Wanted to improve the layout but found that everything was off since I could not load bootstrap...