14

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!)

tUrG0n
  • 4,178
  • 3
  • 20
  • 26
  • That's because other qualified people obviously do not believe it's _"the way to go"_. This type of question is usually not allowed since it will invoke strong opinions. Also, despite it being "not constructive", it's [been addressed here many times before](http://stackoverflow.com/search?q=CDN+good+idea&submit=search). – Sparky Nov 10 '12 at 15:54
  • Look in jQuery tag FAQ in this site... one of the top ranking posts covers this topic in great detail http://stackoverflow.com/questions/1014203/best-way-to-use-googles-hosted-jquery-but-fall-back-to-my-hosted-library-on-go. Simple answer for your question is CDN resources much more likely to already be in user cache – charlietfl Nov 10 '12 at 15:56
  • This question could be rephrased to be constructive if you were ask what the specific technical differences are, so that you can make your own judgement call, rather than asking for others to give your theirs. – eh9 Nov 10 '12 at 16:03
  • thank you for you comments. I re-wrote the question. Thanks @eh9 for the hint ;) – tUrG0n Nov 10 '12 at 16:16
  • This is a perfectly fair question. I googled this exact question. – RJB Sep 15 '16 at 05:22

1 Answers1

5

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.

Brad
  • 159,648
  • 54
  • 349
  • 530