I have a habit of storing everything locally and making sure my site is able to run even on local server without internet connection. This has been my principle ever since so that my site can run stand alone offline, and most specially for developing phase where my page refreshes are super quick and I can continue to develop my sites even without internet.
So in all my web applications and sites, I always download the packages and libraries I need and locally link to them for includes and what not.
I know more and more people are linking / importing libraries via public CDNs and stuff so I was wondering if there's any real SIGNIFICANT benefits to doing that?
I have identified the obvious (feel free to correct me):
PRO LOCAL - faster development experience - zero dependency on other servers that may break - faster user experience (?) since the site pages executes rapidly working with files/libraries on the same server already (localized)
PRO CDN - saves web space (but in today's world, this seems insignificant.. in a typical site you're able to save maybe 10-20mb worth of space only and what is that in the grand scheme of things nowadays and cheap servers and all)
Thanks all.
CDNs are best suited for today's modern websites which involve different types of media files and a combination of static and dynamic content. With a local server hosting your website, the scope is also quite narrow and focused, and you don't have to worry about the nature and configuration of a network of servers.
It is still beneficial to use a CDN, and it is still for your users' benefit, but the benefit is in reduced latency with geo-located servers, not in general performance due to a hot cache hit.
CDNs deliver faster loading speeds for readers. Because this content is readily available, it is pushed to users faster than would be the case in a local website server.
To your question on Best Practices, there are a lot of very good reasons to use a CDN in a production environment: It increases the parallelism available. It increases the chance that there will be a cache-hit. It ensures that the payload will be as small as possible.
The benefit of a CDN is not (and should not be) for you. It is for your customers / users. Using CDN files - especially for widely used libraries like jQuery (or any other big library) - means they will receive a cached copy of the file from a physical location near them. In most cases, using a popular CDN for big libraries means the user has also downloaded that resource before - from someone else's site - so the file will be cached locally in their browser.
This helps reduce the time your user spends downloading files. It is not about your server load or your development ability in all but the smallest margin of edge cases. Think about your users first!
Using a CDN for most static files is strictly better for your users.
Update 2022-01-25:
It's worth noting that while this was true for a long time, it's really not the case any more. There are still real benefits from using CDNs (for example: files are served from a location in close physical proximity to the consuming end-user - on large, globally distributed CDNs), but the cross-domain resource caching is no longer a benefit.
@x-yuri noted this near the end of 2021, and all the major browsers implemented cache partitioning no later than 2020.
It is still beneficial to use a CDN, and it is still for your users' benefit, but the benefit is in reduced latency with geo-located servers, not in general performance due to a hot cache hit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With