Select Page

I have an application written in AngularJS.  It works on my Windows desktop just fine.  It also works on my Android.  However, it would only display the raw HTML (instead of the updated Angular HTML) on Windows Phone.  Turns out that Windows Phone does not like loading AngularJS from a CDN.  More specifically, it does not like loading any files from outside the local site.

As a result, I downloaded the AngularJS zip and included it in my site.  To still take advantage of CDN, I wrote a fallback routine that looks to the CDN first – and if it fails, then falls back to the local version.  Here is the code (in a WordPress installation):

function queue_angular()
{
   $cdn_url = 'https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js';
   $cdn_handle = @fopen( $cdn_url );
   if ( $cdn_handle !== false )
   {
      // CDN exists, so queue it.
      wp_enqueue_script( 'angular_js', 'https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js', array(), null, false );
   }
   else
   {
      // CDN does not exist, so queue the local version.
      wp_enqueue_script( 'angular_js', get_stylesheet_directory_uri().'/angular-1.3.15/angular.min.js', array(), null, false );
   }
}

Windows Phone might be improving security – but at what cost?