Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I have to say as unpopular an opinion as it seems to be I have always stuck to keeping local copies of my core libraries hosted on my server. I know all of the benefits of pulling from a central CDN like Google but I still can't get over the fear of being dependent on an external source for part of my core functionality.


Best of both worlds:

<script src="//example.cdn.com/jquery.min.js"></script> <script>window.jQuery || document.write('<script src="scripts/jquery.min.js"><\/script>') </script>


Argh, No!

That assumes there's a clean fail on the initial request for jQuery i.e. it returns a HTTP error.

What happens when the webserver just doesn't respond? DOM construction is just going to wait until the browser times the connection out before it starts to download the fall back (know as a 3rd Party SPOF)

The time out is 30 seconds plus so essentially the page is broken from the user perspective.


Perhaps a deamon on your server that pings the cdn every minute and checks whether it's down?

If it is, you can flip a switch that tells the code to use the local repositories until the service is back up.


and what about CSS? the link in the initial post shows that CSS is not available via CDN, not JS



I have my own mix of 3rd party libraries I need for my application to run (Bootstrap, JQuery, Lodash, Flot, JQuery-Download, Markdown, etc), it is a large set, but I'm writing a multimedia application!!! Anyway, I find more value in doing my own combining and minification of those dependencies, as opposed to grabbing them individually from 3rd party servers. So my typical page loads with 3 javascript files and one css file.

Also, I've had to work in corporate environments where they would only let VERY specific IP addresses into their network. Javascript files on Google's CDN would routinely get blocked as Google changed IP addresses.

Now I host everything myself and I haven't had an issue.


Why can't we have both?[0]

I'm curious to know if there are any drawbacks to the approach in the linked article.

[0] http://www.hanselman.com/blog/CDNsFailButYourScriptsDontHave...


and what about CSS? the link in the initial post shows that CSS is not available via CDN, not JS [0]

[0] https://news.ycombinator.com/item?id=8552139


This article[0] looks like it supports both (after a cursory glance):

[0] http://eddmann.com/posts/providing-local-js-and-css-resource...


What are those benefits of pulling from a central CDN? I've never understood that, and always hated the idea of yet another point of failure. Especially for something so easy to host yourself.



I know the theoretical reasons, but I'm not sure it makes such a big difference in practice.


If everyone references the CDN copy, then most clients will already have the library cached and don't have to download it separately.

Personally, I self-host every dependency I possibly can, specifically because I don't want my website's functionality, performance, or security to depend on a third party insofar as I possibly can.


The cache-sharing other users are citing is useful, but ultimately not the most-useful part. The most useful feature is the fact that, given tons of sites are now serving global audiences, you as the site owner/administrator no longer have to deal with provisioning servers to datacenters or infrastructure of any sort (for these static resources) nearer to your customers. If you optimize by putting all of these external links into <head> and shipping that bit of your page out earlier than it takes to generate the rest of the page, you'll see pretty solid performance gains for anyone not where YOU are (near your likely us/eu based servers). At some point in optimization the speed of light becomes the hard barrier, and not caching concerns.


Supposedly it's because many sites use jQuery et al so it's already cached in the user's browser. In reality minified bootstrap & jquery scripts/css combined is usually faster than the rest of the site to load anyway, no big deal to just host it locally




Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: