4 ms·
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
by 51Cards 12y ago
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.
- colinbartlett 12y agoWhat 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.
- cheald 12y agoIf 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.
- corobo 12y agoSupposedly 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
- leeber 12y agoThis sums it up nicely: http://encosia.com/3-reasons-why-you-should-let-google-host-jquery-for-you/ http://encosia.com/3-reasons-why-you-should-let-google-host-...
- eloisant 12y agoI know the theoretical reasons, but I'm not sure it makes such a big difference in practice.
- aranjedeath 12y agoThe 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.
- 9point6 12y agoBest 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>
- gondo 12y agoand what about CSS? the link in the initial post shows that CSS is not available via CDN, not JS
- acoyfellow 12y agohttp://stackoverflow.com/questions/10537039/how-to-determine-if-css-has-been-loaded http://stackoverflow.com/questions/10537039/how-to-determine...
- youngtaff 12y agoArgh, 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.
- leke 12y agoPerhaps 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.
- cwbrandsma 12y agoI 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.
- stronglikedan 12y agoWhy 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/CDNsFailButYourScriptsDontHaveToFallbackFromCDNToLocalJQuery.aspx http://www.hanselman.com/blog/CDNsFailButYourScriptsDontHave...
- gondo 12y agoand 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 https://news.ycombinator.com/item?id=8552139
- stronglikedan 12y agoThis article[0] looks like it supports both (after a cursory glance): [0] http://eddmann.com/posts/providing-local-js-and-css-resources-for-cdn-fallbacks/ http://eddmann.com/posts/providing-local-js-and-css-resource...