diff --git a/advagg.admin.inc b/advagg.admin.inc
index d268c66..bc509a0 100644
--- a/advagg.admin.inc
+++ b/advagg.admin.inc
@@ -181,7 +181,7 @@ function advagg_admin_info_form() {
     $path_blacklist = variable_get(CDN_EXCEPTION_DRUPAL_PATH_BLACKLIST_VARIABLE, CDN_EXCEPTION_DRUPAL_PATH_BLACKLIST_DEFAULT);
     $conf[CDN_EXCEPTION_DRUPAL_PATH_BLACKLIST_VARIABLE] = '';
 
-    $url_cdn = file_create_url($filepath);
+    $url_cdn = advagg_build_uri($filepath);
 
     $conf[CDN_EXCEPTION_DRUPAL_PATH_BLACKLIST_VARIABLE] = $path_blacklist;
     // Send request and also time it.
diff --git a/advagg.install b/advagg.install
index 0762c21..9ac2c14 100644
--- a/advagg.install
+++ b/advagg.install
@@ -350,14 +350,14 @@ function advagg_check_missing_handler() {
       $path_blacklist = variable_get(CDN_EXCEPTION_DRUPAL_PATH_BLACKLIST_VARIABLE, CDN_EXCEPTION_DRUPAL_PATH_BLACKLIST_DEFAULT);
       $conf[CDN_EXCEPTION_DRUPAL_PATH_BLACKLIST_VARIABLE] = '';
 
-      $url_cdn_css = file_create_url($css_path . $filepath . '.css');
+      $url_cdn_css = advagg_build_uri($css_path . $filepath . '.css');
       $parts_css = @parse_url($url_cdn_css);
       // Do not test CDN CSS if the hosts are the same.
       if (strcmp($parts_css['host'], $_SERVER['HTTP_HOST']) == 0) {
         $parts_css = FALSE;
       }
 
-      $url_cdn_js = file_create_url($js_path . $filepath . '.js');
+      $url_cdn_js = advagg_build_uri($js_path . $filepath . '.js');
       $parts_js = @parse_url($url_cdn_js);
       // Do not test CDN JS if the hosts are the same.
       if (strcmp($parts_js['host'], $_SERVER['HTTP_HOST']) == 0) {
diff --git a/advagg.module b/advagg.module
index e6cef03..e37aa3c 100644
--- a/advagg.module
+++ b/advagg.module
@@ -1460,11 +1460,22 @@ function advagg_set_file_data($filename_md5, $data) {
  *   data to store.
  */
 function advagg_build_uri($path) {
+  $original_path = $path;
   // CDN Support.
   if (module_exists('cdn')) {
     $status = variable_get(CDN_STATUS_VARIABLE, CDN_DISABLED);
-    if (($status == CDN_ENABLED || ($status == CDN_TESTING && user_access(CDN_PERM_ACCESS_TESTING))) && !variable_get(CDN_THEME_LAYER_FALLBACK_VARIABLE, FALSE)) {
-      return file_create_url($path);
+    if (($status == CDN_ENABLED || ($status == CDN_TESTING && user_access(CDN_PERM_ACCESS_TESTING)))) {
+      // Alter URL when the file_create_url() patch is not there.
+      if (variable_get(CDN_THEME_LAYER_FALLBACK_VARIABLE, FALSE)) {
+        cdn_file_url_alter($path);
+      }
+      // Use the patched version of file_create_url().
+      else {
+        file_create_url($path);
+      }
+      if ($original_path != $path) {
+        return $path;
+      }
     }
   }
   return base_path() . $path;
@@ -2886,7 +2897,7 @@ function advagg_async_connect_http_request($url, array $options = array()) {
  * @param $request
  *   (optional) A string containing the request headers to send to the server.
   * @param $timeout
- *   (optional) An interger holding the stream timeout value.
+ *   (optional) An integer holding the stream timeout value.
  * @return bool
  *   TRUE if function worked as planed.
  */
@@ -3039,7 +3050,7 @@ function advagg_ctools_process_js_files(&$js_files, $scope, $scripts = NULL) {
         // If JS preprocessing is off, we still need to output the scripts.
         // Additionally, go through any remaining scripts if JS preprocessing is on and output the non-cached ones.
         foreach ($data as $path => $info) {
-          // If the script is being replaced, take that replacment into account.
+          // If the script is being replaced, take that replacement into account.
           $final_path = isset($replacements[$type][$path]) ? $replacements[$type][$path] : $path;
           $js_files[base_path() . $final_path] = TRUE;
         }
