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.