Browse files

Add support for multiple fallback CDN locations

  • Loading branch information...
1 parent 7ccfe56 commit 762539aab481899bb58e05c825c5a7958e90bf40 Jason Johnston committed Oct 3, 2011
Showing with 32 additions and 21 deletions.
  1. +4 −4 build.xml
  2. +28 −17 sources/htc_script.js
View
8 build.xml
@@ -3,8 +3,8 @@
<project name="PIE" default="build" basedir=".">
<property name="version" value="1.0beta6-SNAPSHOT" />
- <!--<property name="default_base_url" value="http://cdnjs.cloudflare.com/ajax/libs/css3pie/${version}" />-->
- <property name="default_base_url" value="http://lojjic.github.com/PIE/files/builds/${version}" />
+ <!-- 'http://cdnjs.cloudflare.com/ajax/libs/css3pie/${version}' -->
+ <property name="default_base_urls" value="['http://lojjic.github.com/PIE/files/builds/${version}']"/>
<property name="build_dir" value="./build" />
<property name="src_dir" value="./sources" />
@@ -94,7 +94,7 @@
<replace file="${build_dir}/PIE_uncompressed.htc">
<replacefilter token="$Version$" value="${version}" />
<replacefilter token="$JSVariant$" value="_uncompressed" />
- <replacefilter token="$DefaultBaseUrl$" value="${default_base_url}" />
+ <replacefilter token="$DefaultBaseUrls$" value="${default_base_urls}" />
</replace>
<replace file="${build_dir}/PIE_IE678_uncompressed.js" token="$Version$" value="${version}"/>
<replace file="${build_dir}/PIE_IE9_uncompressed.js" token="$Version$" value="${version}"/>
@@ -125,7 +125,7 @@
<replace file="${build_dir}/PIE.htc">
<replacefilter token="$Version$" value="${version}" />
<replacefilter token="$JSVariant$" value="" />
- <replacefilter token="$DefaultBaseUrl$" value="${default_base_url}" />
+ <replacefilter token="$DefaultBaseUrls$" value="${default_base_urls}" />
</replace>
<replace file="${build_dir}/PIE_IE678.js" token="$Version$" value="${version}"/>
<replace file="${build_dir}/PIE_IE9.js" token="$Version$" value="${version}"/>
View
45 sources/htc_script.js
@@ -6,9 +6,9 @@ var el = element,
if (!PIE && docMode < 10) {
(function() {
var queue = {},
- defaultBaseUrl = '$DefaultBaseUrl$',
+ baseUrls = $DefaultBaseUrls$,
protocol = doc.location.protocol,
- baseUrl, script, tester, isIE6;
+ baseUrl, tester, isIE6, i = 0;
// Create stub PIE object
PIE = window[ 'PIE' ] = {
@@ -30,27 +30,38 @@ if (!PIE && docMode < 10) {
baseUrl = doc.documentElement.currentStyle.getAttribute( ( isIE6 ? '' : '-' ) + 'pie-base-url' );
if( baseUrl ) {
baseUrl = baseUrl.replace(/^"|"$/g, '');
- } else {
- baseUrl = ( protocol === 'https:' ? protocol + defaultBaseUrl.replace( /^[^\/]*]/, '' ) : defaultBaseUrl );
+ baseUrls = [ baseUrl ];
}
- baseUrl += '/PIE_IE' + ( docMode < 9 ? '678' : '9' ) + '$JSVariant$.js';
// Start loading JS file
- script = doc.createElement( 'script' );
- script.async = true;
- script.onreadystatechange = function() {
- var rs = script.readyState, id;
- if ( queue && ( rs === 'complete' || rs === 'loaded' ) ) {
- for( id in queue ) {
- if ( queue.hasOwnProperty( id ) ) {
- PIE[ 'attach' ]( queue[ id ] );
+ function tryLoading( baseUrl ) {
+ var script = doc.createElement( 'script' );
+ script.async = true;
+ script.onreadystatechange = function() {
+ var rs = script.readyState, id;
+ if ( queue && ( rs === 'complete' || rs === 'loaded' ) ) {
+ if ( 'version' in PIE ) {
+ for( id in queue ) {
+ if ( queue.hasOwnProperty( id ) ) {
+ PIE[ 'attach' ]( queue[ id ] );
+ }
+ }
+ queue = 0;
+ } else {
+ tryLoading( baseUrls[ ++i ] );
}
}
- queue = 0;
+ };
+
+ if ( protocol === 'https:' ) {
+ baseUrl = baseUrl.replace( /^http:/, protocol );
}
- };
- script.src = baseUrl;
- ( doc.getElementsByTagName( 'head' )[0] || doc.body ).appendChild( script );
+ script.src = baseUrl + '/PIE_IE' + ( docMode < 9 ? '678' : '9' ) + '$JSVariant$.js';
+ ( doc.getElementsByTagName( 'head' )[0] || doc.body ).appendChild( script );
+ }
+
+ tryLoading( baseUrls[ i ] );
+
})();
}

0 comments on commit 762539a

Please sign in to comment.