Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

when to host using a CDN and when not to? [closed]

Tags:

jquery

bower

cdn

This question tries to find whether its worth to trade-off the benefits of a CDN in favor of a more structured and organized vendor code management.


I know that using a CDN to deliver vendor libs like jquery is recommended.

Yet, I was reading about bower today and It made me wonder. With bower I can easily manage all of the dependencies of my application in a very structured way. I can eventually pack them up in a single vendor.js file (using yeoman, brunch or simple grunt) that will be server in the html in a script tag.

However, while this approach can make my life easier, what are its cons? I can think of the following:

  • There is high chance that many of the libs i'm using, are already cached in the user's browser.
  • By putting it all in a single vendor.js file, the browser will eventually cache this file, but I will start facing problems whenever I add new third-party depencies, ie when my vendor file is changed. The browser will have to reload that file (thus loosing the caching of the original vendor.sj file)

Putting it this way, paying the time to manage dependencies in the html as <script> tags, seams to offer a better performance/load time.

Do you think there is something wrong in my way of thinking? Is the benefit of organizing code with say bower, convincing enough? After all, its like for backbone. Yes a backbone app is heavier for small applications, it contains more code.. but from a dev point of view, its worth it!

Cheers (and thanks for the comments that made me re-edit the question!)

like image 437
tUrG0n Avatar asked Nov 10 '12 15:11

tUrG0n


People also ask

When should a CDN be used?

Anybody who has a website or mobile application that's likely to be requested by more than one user at a time can benefit from a CDN. They are especially useful to large, complex websites with users spread across the globe, and websites or mobile apps with lots of dynamic content.

What is the difference between CDN and hosting?

Traditional web hosting relies on one server, while a CDN leverages a worldwide network of edge servers that disseminate content from a variety of interconnected hosts. The last difference is in the amount of content each option delivers.

Should I use a CDN for my website?

Keep in mind that a CDN is necessary if your company fits in with only one of the points. You should seriously consider a CDN if: Your site is growing at an exponential rate – A regular server is going to have a tough time handling a spike in traffic, unless you prepare for it with a CDN.


1 Answers

Use a CDN when it is available to you and is allowed by your project's requirements. It is generally faster, and browsers will have likely cached those files from other sites already.

Most sites I build, I use jQuery from the CDN. However, you will find that sometimes those CDNs are blocked by specific countries. In any case, it doesn't hurt to have a fallback. You can load jQuery from a CDN, and fallback to your own server if that fails.

like image 83
Brad Avatar answered Sep 27 '22 21:09

Brad