Important Note

This tutorial assumes you have already created a Pull Zone.

This CDN implementation is using the default skin called “ideal_comfort,” so if you are using another skin you will need to modify the code shown below to match the name of your skin.

X-Cart 4.4.x (and later) + CDN implementation – fixed path to skin

  1. Open the core X-Cart file “smarty.php,” located in root directory of X-Cart.
  2. Find the following two lines:
    $smarty->assign('ImagesDir',        $xcart_web_dir . $smarty_skin_dir . '/images');
            $smarty->assign('SkinDir',          $xcart_web_dir . $smarty_skin_dir);
  3. Replace these two lines with the following:
    // WCM - MaxCDN Implementation
            if ($_SERVER['HTTPS'] != 'on')
            {
            $smarty->assign("SkinDir","http://foo.bar.netdna-cdn.com/skin/ideal_comfort");
            $smarty->assign("ImagesDir","http://foo.bar.netdna-cdn.com/skin/ideal_comfort/images");
            }
            else
            {
            $smarty->assign("SkinDir",$xcart_web_dir."/skin/ideal_comfort");
            $smarty->assign("ImagesDir",$xcart_web_dir."/skin/ideal_comfort/images");
            }
  4. Note that “foo.bar.netdna-cdn.com” needs to be replaced with the proper CDN temp URL or, if you have a custom URL, the proper custom URL. You can check if your X-Cart is using the CDN by loading it in browser and viewing the source code of the page.

X-Cart 4.4.x (and later) + CDN implementation – dynamic skin path

If you want your skin path to be assigned dynamically, follow these steps:

  1. Open the core X-Cart file “smarty.php,” located in root directory of X-Cart.
    1. Find the following two lines:
      $smarty->assign('ImagesDir',        $xcart_web_dir . $smarty_skin_dir . '/images');
                      $smarty->assign('SkinDir',          $xcart_web_dir . $smarty_skin_dir);
    2. Replace these two lines with following:
      // WCM - MaxCDN Implementation
                      if ($_SERVER['HTTPS'] != 'on')
                      {
                      $smarty->assign('ImagesDir',        "http://foo.bar.netdna-cdn.com" . $smarty_skin_dir . '/images');
                      $smarty->assign('SkinDir',          "http://foo.bar.netdna-cdn.com" . $smarty_skin_dir);
                      }
                      else
                      {
                      $smarty->assign('ImagesDir',        $xcart_web_dir . $smarty_skin_dir . '/images');
                      $smarty->assign('SkinDir',          $xcart_web_dir . $smarty_skin_dir);
                      }
  2. Utilize CDN for css and js files (*/var/cache/*)
    1. Open /include/templater/plugins/function.load_defer_code.php and locate the following line:
      $cacheWebFile = $var_dirs_web['cache'] . '/' . $label . '.' . $md5Suffix . '.' . $type;
    2. Replace that line with the following:
      if ($_SERVER['HTTPS'] != 'on') 
                      { 
                      $cacheWebFile = "http://foo.bar.netdna-cdn.com/var/cache" . '/' . $label . '.' . $md5Suffix . '.' . $type; 
                      } 
                      else 
                      { 
                      $cacheWebFile = $var_dirs_web['cache'] . '/' . $label . '.' . $md5Suffix . '.' . $type; 
                      }
  3. Utilize CDN for “W”, “D”, “P” and “T” types of images
    1. Open /include/func/func.files.php and find the following line:
      global $config, $sql_tbl, $xcart_dir, $current_location;
    2. ADD these new lines below (DON’T replace with but ADD below it)
      if ($HTTPS) 
                      $current_location = $current_location; 
                      else 
                      $current_location = 'http://foo.bar.netdna-cdn.com';
  4. Utilize CDN for “C” type of image file
    1. Open /include/templater/plugins/function.get_category_image_url.php and find the following line:
      return func_convert_amp(func_get_image_url($category['categoryid'], 'C', $category['image_path']));
    2. Replace that line with the following:
      return return str_replace("domain.com ","foo.bar.netdna-cdn.com",func_convert_amp(func_get_image_url($category['categoryid'], 'C', $category['image_path'])));
  5. Utilize CDN for “A” type of image files
    1. Open /skin/common_files/modules/Banner_System/banner_rotator.tpl and find the following line:
      src="{$content.image_path|amp}"
    2. Replace that line with the following:
      src="{$content.image_path|amp|replace:'domain.com':'foo.bar.netdna-cdn.com'}"
    3. “foo.bar.netdna-cdn.com” needs to be replaced with proper CDN temp URL or, if you have a custom URL, the proper custom URL. Also, “domain.com” has to be replaced by your actual origin server URL.

      NOTE

      To ensure you implemented MaxCDN correctly, you can view the source code of any page to confirm that the CDN domain is being used for static assets instead of your origin domain. You can also use tools like pingdom, gtmetrix, webpagetest that can give you more detailed reports on your CDN implementation status.

      This CDN implementation is using the default skin called “skin1,” so if you are using another skin you will need to modify the code shown below to match the name of your skin.

X-Cart 4.3.x CDN implementation

  1. Open the core X-Cart file “smarty.php,” located in root directory of X-Cart.
  2. Find the following two lines:
    $smarty->assign("SkinDir",$xcart_web_dir."/skin1");
            $smarty->assign("ImagesDir",$xcart_web_dir."/skin1/images");
  3. Replace these two lines with following:
    // WCM - MaxCDN Implementation
            if ($_SERVER['HTTPS'] != 'on')
            {
            $smarty->assign("SkinDir","http://foo.bar.netdna-cdn.com/skin1");
            $smarty->assign("ImagesDir","http://foo.bar.netdna-cdn.com/skin1/images");
            }
            else
            {
            $smarty->assign("SkinDir",$xcart_web_dir."/skin1");
            $smarty->assign("ImagesDir",$xcart_web_dir."/skin1/images");
            }
  4. Proceed with steps 2 – 5 as shown in “X-Cart 4.4.x (and later) + CDN implementation – dynamic skin path.”
“foo.bar.netdna-cdn.com” needs to be replaced with proper CDN temp URL or, if you have custom URL, the proper custom URL. You can check if your X-Cart is using CDN by loading it in browser and viewing the source code.

NOTE

To ensure you implemented MaxCDN correctly, you can view the source code of any page to confirm that the CDN domain is being used for static assets instead of your origin domain. You can also use tools like pingdom, gtmetrix, webpagetest that can give you more detailed reports on your CDN implementation status.