Forums
View unanswered posts | View active topics It is currently Fri Jul 25, 2014 2:58 am



Reply to topic  [ 7 posts ] 
 Why a CDN? 
Author Message

Joined: Tue May 17, 2011 1:35 pm
Posts: 27
Post Why a CDN?
Hi Jason & company,
I have noticed that upon reading the various threads, that you all are looking at putting PIE on a CDN. My question is: why? I understand about content availability, etc, etc., but, why would I want to reference PIE on a CDN instead of hosting it on my own server? Making another 'network' call has got to be more expensive (time wise) than fetching from my own server. I can't imagine the reason would be to always have the latest version since that would mean possibly running an untested version in a live environment. I must be missing something. I can't see the benefits of not hosting PIE locally. Could you or someone enlighten me?

Keep up the excellent work...
Dick


Sat Mar 02, 2013 3:45 pm
Profile

Joined: Wed Jul 14, 2010 11:46 am
Posts: 1441
Post Re: Why a CDN?
First of all: using a CDN-hosted version of the JS files is completely optional and up to the individual -- by default it loads from the main domain.

Now... using a CDN can have several benefits, including:
- They can serve the content from the server closest geographically to each site visitor
- Avoids using up one of the concurrent connections that IE allows to your main domain, so other resources can download from your server in parallel
- CDNs generally have proper Gzipping enabled, which many users might not have the knowledge or ability to configure on their own server

These are all really standard reasons for using CDNs, nothing specific to PIE. And of course the usual tradeoffs apply too -- like you mentioned the possibly extra DNS lookup, plus the dependency on a third party's service. But I think it's still a valuable option to provide, especially since it sort of comes "for free" as a nice bonus from the new loading system.


Sat Mar 02, 2013 9:58 pm
Profile

Joined: Wed Mar 13, 2013 5:18 am
Posts: 2
Post Re: Why a CDN?
I must say I’ve grown tired of the annoying trend to increasinly outsource even simplest scripts to CDNs. This requires connection to third party servers to execute these scripts which some people – like me – have deliberately disabled. And more and more sites become completely unusable because some lazy developer or ignorant n00b just puts a link to an external CDN in their websites without even thinking of a local fallback solution (despite the fact that they write crappy code so that the working of their website relies on JavaScript). I’ve seen someone in a comment to the 2.0 announcement asking about a CDN and this alone shows how lazy and ignorant people have become. They don’t even want to think about how to implement a script, they just wanna put a link to somewhere. In my opinion those people don’t deserve to use it if they don’t care about anything.

I see no advantage whatsoever to serve CSS3PIE from a CDN. I can understand that for large applications like video streaming servers or whatever but not for a comparably small script like CSS3PIE.
Sorry for the rant but I had to get that out of my system.


Wed Mar 13, 2013 5:44 am
Profile

Joined: Wed Jul 14, 2010 11:46 am
Posts: 1441
Post Re: Why a CDN?
While I agree with you that blindly using CDNs without properly considering the tradeoffs is naive (this is why PIE does not use a CDN by default), I also think that the "CDNs have no benefit, never use them" attitude is similarly naive. As I mentioned above, there are some real benefits to using CDNs, as well as some real downsides, and calling those who make that choice responsibly "ignorant" or "lazy" is unfair.

You bring up some good points, so let's discuss these:

- You say you disable scripts from other domains. I'm unfamiliar, is this an option in IE? How do you set it? Is there a way to detect in code when a user has that setting enabled, so that PIE can automatically fall back to local loading? I'll gladly implement that if possible.

- I sympathize with your concern about reliance on third-party servers. That becomes a real problem if the scripts are loaded synchronously, or if the site can't function without the scripts. With PIE, however, neither of these is an issue in my opinion -- if it's configured to load from an external domain it will do so asynchronously so the page is not blocked from rendering, and PIE only provides visual effects which shouldn't ever prevent site functionality anyway.

Also, let's not fall into the trap of assuming that "separate domain" equals "third-party server". It's quite possible (and I think somewhat common) to use several domains that resolve to the same physical server or cluster, to enable the technique known as "domain sharding" to get around concurrent connection limits imposed by browsers -- I've done this in the past and it can improve site performance significantly, especially in old IE where the connection limit is low.

All good discussion. :) If anyone wants to take a whack at drafting some guidelines on the pros/cons of loading from external domains, I think that would be a valuable resource for PIE users and I'd gladly include it in our docs.


Wed Mar 13, 2013 11:25 am
Profile

Joined: Wed Mar 13, 2013 5:18 am
Posts: 2
Post Re: Why a CDN?
jason wrote:
While I agree with you that blindly using CDNs without properly considering the tradeoffs is naive (this is why PIE does not use a CDN by default), I also think that the "CDNs have no benefit, never use them" attitude is similarly naive. As I mentioned above, there are some real benefits to using CDNs, as well as some real downsides, and calling those who make that choice responsibly "ignorant" or "lazy" is unfair.

I’m not saying that CDNs have no benefit and I’m not saying I never use them. Those who make the choice responsibly deserve all my respect. However, according to my experience this is a real minority and I see too many people with that lazy attitude around these days. With developments like Modernizr, HTML 5 boilerplate, jQuery, SASS/LESS etc. and everything served from CDNs with just a copy/paste it has become just too easy to negligently throw something together without much thinking, and that actually puts even more load on the user’s bandwidth and/or browser. It’s just so sad to see something useful being misused just because it can be done.

jason wrote:
- You say you disable scripts from other domains. I'm unfamiliar, is this an option in IE? How do you set it?

To be honest, I’m using Firefox with the NoScript add-on. But I seem to remember a setting in Safari where you can disable third party scripts (or was it just for cookies?). But anyway, there are script blocking extensions for every major browser out there nowadays, and these have received an increasing popularity for exactly that reason: because it has become annoying how many scripts are being loaded and make sites slow and bloated, track you down, and annoy you with ads. And if someone is using Cloudfront to serve their useful scripts that doesn’t mean someone else wouldn’t use it to serve suspicious or unnecessary scripts. So you have the choice to either block Cloudfront altogether and risk some legitimate but badly coded sites to not work anymore or to accept suspicious scripts from other websites.

jason wrote:
Is there a way to detect in code when a user has that setting enabled, so that PIE can automatically fall back to local loading? I'll gladly implement that if possible.

I’ve worked with jQuery in the past where I checked for the presence of the jQuery object/function and if not present would load a local fallback copy. The code looks something like this:
Code:
function include(file, callback) {
   var head         = document.getElementsByTagName('head')[0];
   var script      = document.createElement('script');
   script.type    = 'text/javascript';
   script.src      = file;
   script.onload = script.onreadystatechange = function() {
      if (callback) callback();
      // prevent memory leak in IE
      head.removeChild(script);
      script.onload = null;
   };
   head.appendChild(script);
}
if(typeof jQuery==="undefined"){
   include('js/jquery.min.js', runScript);
}
else {
   runScript();
}

Where runScript() is the function that holds all my custom JS. That code above would be included after the script reference to the CDN.

jason wrote:
- I sympathize with your concern about reliance on third-party servers. That becomes a real problem if the scripts are loaded synchronously, or if the site can't function without the scripts. […]

Also, let's not fall into the trap of assuming that "separate domain" equals "third-party server". It's quite possible (and I think somewhat common) to use several domains that resolve to the same physical server or cluster, to enable the technique known as "domain sharding" to get around concurrent connection limits imposed by browsers -- I've done this in the past and it can improve site performance significantly, especially in old IE where the connection limit is low.

In those projects where I was involved I have never had a noticeable performance hit with loading scripts synchronously (I even reference my scripts in the document head out of personal preference) but maybe that’s because I’m not randomly adding hundreds of third party widgets and what not. And I even think this speed argument is kind of construed by nerds that feel joy by analyzing scripts all day and care about microseconds of loading time.
And you are right, CSS3PIE is not that crucial for the functioning of a website. I just wanted to express my concern that, if one makes it seem too simple to use something, the likelihood of it being used improperly is much bigger, which is the case with the increasing move towards CDNs for every minor script someone provides.


Wed Mar 13, 2013 6:41 pm
Profile

Joined: Wed Jul 14, 2010 11:46 am
Posts: 1441
Post Re: Why a CDN?
Quote:
But anyway, there are script blocking extensions for every major browser out there nowadays
...
I’ve worked with jQuery in the past where I checked for the presence of the jQuery object/function and if not present would load a local fallback copy. The code looks something like this:


Thanks, I'll look into installing a script blocking extension for IE to test with, and I'll give your code approach a shot.

Quote:
In those projects where I was involved I have never had a noticeable performance hit with loading scripts synchronously


I was referring to synchronously loading scripts from third-party CDNs. The issue is that if the third-party CDN goes down, and you load a script from it in a script tag in the head of your markup, then your page will block loading and won't continue until the CDN request times out. Sync loading of scripts from a domain you control isn't as much of an issue. And as I said, since PIE loads async, it won't block your page even if the CDN goes down.

Quote:
And I even think this speed argument is kind of construed by nerds that feel joy by analyzing scripts all day and care about microseconds of loading time.


That made me laugh. :lol: I'd never say I got "joy" out of that sort of analysis, but I can tell you that I've seen real loading time improvements in *seconds* using sharding for users on slow connections. Don't dismiss it so readily.

Quote:
And you are right, CSS3PIE is not that crucial for the functioning of a website. I just wanted to express my concern that, if one makes it seem too simple to use something, the likelihood of it being used improperly is much bigger, which is the case with the increasing move towards CDNs for every minor script someone provides.


I think that's a risk I'm willing to take. :) If you're concerned about abuse, I'd welcome your help in drafting a guide to help users make the decision responsibly.


Thu Mar 14, 2013 8:30 am
Profile

Joined: Fri Mar 15, 2013 4:02 am
Posts: 1
Post Re: Why a CDN?
Very refreshing to see people actually discussing CDNs rationally rather than blindly using them without any real consideration of their apparent benefit.

This article might make an interesting read for some here http://zoompf.com/2010/01/should-you-us ... brary-cdns - lots of good counter-points in the comments underdneath too.


Fri Mar 15, 2013 4:09 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 7 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.