The following guide will walk you through implementing X-Cart with MaxCDN.
This tutorial assumes you have already created a Pull Zone.
4.4.x (and later)
- CDN implementation - fixed path to skin
- Open the core X-Cart file
smarty.php
, located in the root directory of X-Cart. - Find the following two lines:
$smarty->assign('ImagesDir', $xcart_web_dir . $smarty_skin_dir . '/images'); $smarty->assign('SkinDir', $xcart_web_dir . $smarty_skin_dir);
- 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"); }
- Open the core X-Cart file
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.
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 the browser and viewing the source code
- CDN implementation - dynamic skin path
If you want your skin path to be assigned dynamically, follow these steps:
- Open the core X-Cart file
smarty.php
located in the root directory of X-Cart.
- Find the following two lines:
$smarty->assign('ImagesDir', $xcart_web_dir . $smarty_skin_dir . '/images'); $smarty->assign('SkinDir', $xcart_web_dir . $smarty_skin_dir);
- Replace these two lines with the 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); }
- Find the following two lines:
- Utilize CDN for .css and .js files
*/var/cache/*
- Open /include/templater/plugins/function.load_defer_code.php and locate the following line:
$cacheWebFile = $var_dirs_web['cache'] . '/' . $label . '.' . $md5Suffix . '.' . $type;
- 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; }
- Open /include/templater/plugins/function.load_defer_code.php and locate the following line:
- Utilize CDN for “W”, “D”, “P” and “T” types of images
- Open /include/func/func.files.php and find the following line:
global $config, $sql_tbl, $xcart_dir, $current_location;
- 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';
- Open /include/func/func.files.php and find the following line:
- Utilize CDN for “C” type of image file
- 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']));
- 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'])));
- Open /include/templater/plugins/function.get_category_image_url.php and find the following line:
- Utilize CDN for “A” type of image files
- Open /skin/common_files/modules/Banner_System/banner_rotator.tpl and find the following line:
src="{$content.image_path|amp}"
- Replace that line with the following:
src="{$content.image_path|amp|replace:'domain.com':'foo.bar.netdna-cdn.com'}"
- Open /skin/common_files/modules/Banner_System/banner_rotator.tpl and find the following line:
- Open the core X-Cart file
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.
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.
4.3.x CDN Implementation
- Open the core X-Cart file
smarty.php
, located in the root directory of X-Cart.
- Find the following two lines:
$smarty->assign("SkinDir",$xcart_web_dir."/skin1"); $smarty->assign("ImagesDir",$xcart_web_dir."/skin1/images");
- Replace these two lines with the 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"); }
- Proceed with steps 2 - 5 as shown in "X-Cart 4.4.x (and later) + CDN implementation - dynamic skin path."
- Find the following two lines:
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.
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
As always, If you have any questions or concerns about any of the topics mentioned in this article, please feel free to reach out to support - we are available 24/7 by chat or email.