According to X-Cart's help wiki: "Setting up a CDN for your medium to large X-Cart site will help improve its loading times across the world by delivering static content from the [StackPath] server located closest to your customer."
This article will walk you through how to perform a static assets integration, which does not support the use of the StackPath Web Application Firewall (WAF). If you’re looking to maximize security by using our CDN with the WAF, please refer to the CDN & WAF integration guide.
In each section of this tutorial, swap site.company.stackpathdns.com
in the code with your Edge Address and yourdomain.com
with your actual domain name. Also, replace ideal_comfort
in the code with the name of your skin if you're not using the Ideal Comfort skin.
Before you begin, we highly recommend you test the performance of your site using Google Page Speed or Pingdom Tools. You can test your site now and after setting up the plugin for a before and after performance comparison.
This tutorial assumes you are using X-Cart 4.4 and later and have already gone through the steps to create a StackPath Site.
Fixed Skin Path
-
Open the core X-Cart file called
smarty.php
.It's located in root directory of X-Cart.
-
Find these two lines:
$smarty->assign('ImagesDir', $xcart_web_dir . $smarty_skin_dir . '/images'); $smarty->assign('SkinDir', $xcart_web_dir . $smarty_skin_dir);
-
Replace them with this code:
// WCM - StackPath Integration if ($_SERVER['HTTPS'] != 'on') { $smarty->assign("SkinDir","http://something.stackpathcdn.com/skin/ideal_comfort"); $smarty->assign("ImagesDir","http://something.stackpathcdn.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"); }
- Verify StackPath is properly integrated.
Dynamic Skin Path
If you want your skin path assigned dynamically, follow the steps in this section.
-
Open the core X-Cart file called
smarty.php
.It's located in root directory of X-Cart.
-
Find these two lines:
$smarty->assign('ImagesDir', $xcart_web_dir . $smarty_skin_dir . '/images'); $smarty->assign('SkinDir', $xcart_web_dir . $smarty_skin_dir);
-
Replace them with this code:
// WCM - MaxCDN Implementation if ($_SERVER['HTTPS'] != 'on') { $smarty->assign('ImagesDir', "http://something.stackpathcdn.com" . $smarty_skin_dir . '/images'); $smarty->assign('SkinDir', "http://something.stackpathcdn.com" . $smarty_skin_dir); } else { $smarty->assign('ImagesDir', $xcart_web_dir . $smarty_skin_dir . '/images'); $smarty->assign('SkinDir', $xcart_web_dir . $smarty_skin_dir); }
-
Open
/include/templater/plugins/function.load_defer_code.php
and find this line:$cacheWebFile = $var_dirs_web['cache'] . '/' . $label . '.' . $md5Suffix . '.' . $type;
-
Replace it with this code:
if ($_SERVER['HTTPS'] != 'on') { $cacheWebFile = "http://something.stackpathcdn.com/var/cache" . '/' . $label . '.' . $md5Suffix . '.' . $type; } else { $cacheWebFile = $var_dirs_web['cache'] . '/' . $label . '.' . $md5Suffix . '.' . $type; }
-
Open
/include/func/func.files.php
and find this line:global $config, $sql_tbl, $xcart_dir, $current_location;
- Add this new code below it. (DO NOT replace.)
if ($HTTPS) $current_location = $current_location; else $current_location = 'http://something.stackpathcdn.com';
-
Open
/include/templater/plugins/function.get_category_image_url.php
and find this line:return func_convert_amp(func_get_image_url($category['categoryid'], 'C', $category['image_path']));
-
Replace it with this code:
return return str_replace("domain.com ","something.stackpathcdn.com",func_convert_amp(func_get_image_url($category['categoryid'], 'C', $category['image_path'])));
- Open
/skin/common_files/modules/Banner_System/banner_rotator.tpl
and find this line:src="{$content.image_path|amp}"
-
Replace it with this code:
src="{$content.image_path|amp|replace:'domain.com':'something.stackpathcdn.com'}"
Test if Stackpath CDN is integrated correctly
Checking if CDN enabled is really simple.
- Purge the browser cache or use a Private or Incognito window.
- Open the website
- Right-click anywhere on the page
- View source code
- Check the source code for the Edge Address
Test speed and SEO after Stackpath CDN is enabled
At this time, you should perform another speed test by using Google Page Speed and Pingdom Tools.
Compare the before and after tests and note that it can take one to seven days for your site to reflect the performance improvements of a CDN. Both of these test sites also will give you SEO recommendations that you can follow.