X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Third Party Add-Ons for X-Cart 4 (https://forum.x-cart.com/forumdisplay.php?f=45)
-   -   MAX cdn (https://forum.x-cart.com/showthread.php?t=64443)

carpeperdiem 01-13-2013 08:00 AM

Re: MAX cdn
 
Sorry to keep posting -- hoping someone jumps in on this...

I was not able to get the detailed images (colorbox) working.

I tried editing these files, using the smarty 'replace' command as used elsewhere:

/common_files/modules/Detailed_Product_Images/product_images.tpl
/common_files/modules/Detailed_Product_Images/colorbox_image.tpl
/common_files/modules/Detailed_Product_Images/popup_image.tpl

and replaced

{$i.image_url|amp}

with
Code:

{$i.image_url|amp|replace:'www.domain.com':'cdn.domain.com'}
...and that was a big old fail. The images are not served from the cdn. Hmm...

Maybe this needs a php solution after all?

carpeperdiem 01-13-2013 08:16 AM

Re: MAX cdn
 
OK -- another roadblock:

Images that are hard coded into the product description...

Since you can't use {$AltImagesDir} in the product description, I use a dedicated directory for all images that need to be hardcoded for the product description:

/product-images/

So I need to figure out how to get all of these images from the product description to the CDN

I guess it's gonna have to be the good old, <img src="http://cdn.domain.com/product-images/image.jpg" />, right? Fortunately, I only have 20 product pages - and only 8 needed edits. Took 5 minutes. And these pages now load faster. Just like that.

3 steps forward, 2 steps back.

totaltec 01-13-2013 09:35 AM

Re: MAX cdn
 
Quote:

Originally Posted by carpeperdiem
Since you can't use {$AltImagesDir} in the product description...

I haven't tested this at all, but could you use eval to include the variable?
Like in this thread: http://forum.x-cart.com/showthread.php?t=21027&highlight=eval

carpeperdiem 01-13-2013 09:42 AM

Re: MAX cdn
 
Quote:

Originally Posted by totaltec
I haven't tested this at all, but could you use eval to include the variable?


Thanks, Mike -- but I am not using variables here... just a path to an image directory. And there is no need to make a var out of this since I hard coded the path initially.
Thanks for the suggestion though... The more I edit templates integrating the CDN, the more I realize this is a much needed part of the core code that should be a checkbox and a one line text input.

Once you see the metrics comparing stock xcart vs. xcart with CDN, your jaw will drop. You can spend days (weeks) optimizing php code and templates, or you can spend minutes turning on the CDN. It's that big a deal. In my case more than 50% reduction in page load time! :-)

carpeperdiem 01-13-2013 12:31 PM

Re: MAX cdn
 
What is the best practice for MaxCDN settings:

SEO robots.txt -- disabled? But is that logical? I want my images indexed. But if the URL for the image is a cache file, that's not good...

Set Default Cache Time: 7 days? Longer? Product images are static and rarely change. Homepage banner images can change daily, or not. Is there a best practice for this?

What does Google see when it finds cached images?

Thinking out loud.
Thanks,
J

carpeperdiem 01-14-2013 12:48 PM

Re: MAX cdn
 
Still trying to solve this -- anyone have any ideas?

Quote:

Originally Posted by carpeperdiem
Slight problem here that hopefully someone can help solve...

This code works -- until you go https at checkout, and then it's a mess (css disappears).

I tried the following, but this cased a server error:

PHP Code:

/* MaxCDN edit - comment out next two lines
            ? '<script type="text/javascript" src="' . $cacheWebFile . '"></script>'
            : '<link rel="stylesheet" type="text/css" href="' . $cacheWebFile . '" />';
*/
// Then insert the following:
if ($_SERVER['HTTPS'] != 'on') {
            ? 
'<script type="text/javascript" src="' str_replace("www.domain.com","cdn.domain.com",$cacheWebFile) . '"></script>'
            
'<link rel="stylesheet" type="text/css" href="' str_replace("www.domain.com","cdn.domain.com",$cacheWebFile) . '" />';
}
else
{
            ? 
'<script type="text/javascript" src="' $cacheWebFile '"></script>'
            
'<link rel="stylesheet" type="text/css" href="' $cacheWebFile '" />';



Hmm... must be my php syntax, right? Isn't this how to do an if? What am I missing? Thanks!
Jeremy


cellswag 01-14-2013 04:02 PM

Re: MAX cdn
 
What about getting the product images to show up using the CDN in the root images folder T and P?

carpeperdiem 01-14-2013 04:10 PM

Re: MAX cdn
 
Quote:

Originally Posted by cellswag
What about getting the product images to show up using the CDN in the root images folder T and P?


For the T thumbs, I followed the suggestion from post #31

Then added the https code as follows:

I used this code for the Thumbs (trapping for https):

Code:

FILE:
/skin/common_files/product_thumbnail.tpl

FIND:
{$tmbn_url|amp}

REPLACE WITH:

{* MaxCDN edit - comment out next line *}
{* {$tmbn_url|amp} *}
{if $smarty.server.HTTPS ne "on"}
{$tmbn_url|amp|replace:'www.domain.com':'cdn.domain.com'}
{else}
{$tmbn_url|amp}
{/if}
{* END MaxCDN edit *}


cellswag 01-14-2013 04:14 PM

Re: MAX cdn
 
Quote:

Originally Posted by carpeperdiem
For the T thumbs, I followed the suggestion from post #31

Then added the https code as follows:

I used this code for the Thumbs (trapping for https):

Code:

FILE:
/skin/common_files/product_thumbnail.tpl

FIND:
{$tmbn_url|amp}

REPLACE WITH:

{* MaxCDN edit - comment out next line *}
{* {$tmbn_url|amp} *}
{if $smarty.server.HTTPS ne "on"}
{$tmbn_url|amp|replace:'www.domain.com':'cdn.domain.com'}
{else}
{$tmbn_url|amp}
{/if}
{* END MaxCDN edit *}



I have that set, but its not showing. For Thumbnails, category images, or detailed. Anything else im missing?

carpeperdiem 01-14-2013 04:22 PM

Re: MAX cdn
 
Quote:

Originally Posted by cellswag
I have that set, but its not showing. For Thumbnails, category images, or detailed. Anything else im missing?


Did you set the CNAME record in cPanel? Are you using cdn.domain.com as an alias for "company.company.netdna-cdn.com" ?

If you have it set correctly, if you view your page source, almost immediately, what was:
Code:

<img src="http://www.domain.com/images/T/xctmp0O7ydz.jpg"
becomes
Code:

<img src="http://cdn.domain.com/images/T/xctmp0O7ydz.jpg"

Are you seeing anything sent to the cdn?

cellswag 01-14-2013 04:25 PM

Re: MAX cdn
 
Hey,

Yes I am using a CName record for this.

I fixed it using

include/func/func.files.php

Quote:

PHP Code:
/**
* Get thumbnail URL (if images are stored on the FS only)
*/
function func_get_image_url($id, $type = 'T', $image_path = false)
{
global $config, $sql_tbl, $xcart_dir, $current_location;

/** CDN support for smarty BEGIN */
if ($HTTPS)
$current_location = $current_location;
else
$current_location = 'http://yourstore.yourstore.netdna-cdn.com';
/* CDN support for smarty END */

if (is_null($image_path))
return func_get_default_image($type);

however, on_sale.php is not showing the correct images since for some reason it is not using FS.

http://domain.com/image.php?type=T&id=18816

carpeperdiem 01-14-2013 04:40 PM

Re: MAX cdn
 
Quote:

Originally Posted by cellswag
however, on_sale.php is not showing the correct images since for some reason it is not using FS


It was 2am when I configured this -- so I am not sure why I chose to use the template edits vs. the php -- but the php is clearly the better solution.

I removed the https edit from the thumb template and all is perfect.

W (variant)
D (detailed)
P (product)
T (thumbs - which for my store is also used as main image)

All good now.

The only thing left for my integration is the cached js and css.

DId you see post #37? ANy ideas how to solve this? Thanks to all for sharing.

cellswag 01-14-2013 04:51 PM

Re: MAX cdn
 
in regards to #37, maybe a skin issue? I am using a custom skin and am not having issues right now with https

Quote:



$result = ('js' == $type)
? '<script type="text/javascript" src="' . str_replace("www.domain.com","cdn.domain.com",$cac heWebFile) . '"></script>'
: '<link rel="stylesheet" type="text/css" href="' . str_replace("www.domain.com","cdn.domain.com",$cac heWebFile) . '" />';



try that?

dave01978 01-15-2013 08:55 PM

Re: MAX cdn
 
this is what the end of my file looks like, i am to tired to edit all out so this is what i am using and is working, thanks for coming up with a solution for the images, i spend hours trying to get that (i am not really much of a programmer, basic little hacks is about all i can do

Code:

// WCM - MaxCDN Implementation
if ($_SERVER['HTTPS'] != 'on')

{
$result = ('js' == $type)
            ? '<script type="text/javascript" src="' . str_replace("www.waterlesscarwashproducts.com","driwash.waterlesscarwashproducts.com",$cacheWebFile) . '"></script>'
            : '<link rel="stylesheet" type="text/css" href="' . str_replace("www.waterlesscarwashproducts.com","driwash.waterlesscarwashproducts.com",$cacheWebFile) . '" />';
}
else
{
        $result = ('js' == $type)
            ? '<script type="text/javascript" src="' . $cacheWebFile . '"></script>'
            : '<link rel="stylesheet" type="text/css" href="' . $cacheWebFile . '" />';
}
    } else {

        $result = '';

    }

    return $result;
}
?>


dave01978 01-15-2013 08:59 PM

Re: MAX cdn
 
Also adding it to the images almost seems to drop the load time in about half from high 2's to mid 1's

carpeperdiem 01-17-2013 12:40 PM

Re: MAX cdn
 
Thanks Dave!
I had a syntax issue...

I thought I could if/else within the function -- but by your example, there is an if, then the else -- and the

$result = ('js' == $type)

is repeated on the else. I'm not a php coder either, but always learning.

THANKS! for the contribution to this thread.
I will try to assemble a master list of edits for 4.5.4 and see if anything is missing.

Thanks!

Jeremy

carpeperdiem 01-17-2013 06:43 PM

Re: MAX cdn
 
Here is my list of MaxCDN edits for my 4.5.4 store.
I have the X-Cart Banner mod, and these images MUST live in the file system for MaxCDN.
This is a collection of edits as contributed by many others here -- but here is what I am using, all in one post...
Hope this helps someone the way other posts here have helped me.

Setting Up MaxCDN -- make a CNAME record in cPanel to simplify the URL and make it looks like: cdn.domain.com (as opposed to companyname.companyname.netdna-cdn.com)

http://cp3support.netdna.com/tutorials/create-cname/

1. file: /smarty.php

FIND:
PHP Code:

$smarty->assign('ImagesDir',        $xcart_web_dir $smarty_skin_dir '/images');
$smarty->assign('SkinDir',          $xcart_web_dir $smarty_skin_dir); 


REPLACE WITH:
PHP Code:

// MaxCDN - next two lines commented out
//$smarty->assign('ImagesDir',        $xcart_web_dir . $smarty_skin_dir . '/images');
//$smarty->assign('SkinDir',          $xcart_web_dir . $smarty_skin_dir);
// MaxCDN add the following
if ($_SERVER['HTTPS'] != 'on'

$smarty->assign('ImagesDir',    "http://cdn.domain.com" $smarty_skin_dir '/images'); 
$smarty->assign('SkinDir',        "http://cdn.domain.com" $smarty_skin_dir); 
$smarty->assign("AltImagesDir",    "http://cdn.domain.com/skin/books_and_magazines/images"); 
$smarty->assign("AltSkinDir",    "http://cdn.domain.com/skin/books_and_magazines"); 

else 

$smarty->assign('ImagesDir',        $xcart_web_dir $smarty_skin_dir '/images'); 
$smarty->assign('SkinDir',          $xcart_web_dir $smarty_skin_dir); 
}  
// END MaxCDN edit 

----------

note:
a) change "cdn.domain.com" to your cdn.domain.com
b) change /skin/books_and_magazines/ to your skin -- if you use "3-columns" - the path would be /skin/3-columns/ etc...

==================================
2. For css and js code

file: /include/templater/plugins/function.load_defer_code.php

FIND:
PHP Code:

$result = ('js' == $type)
            ? 
'<script type="text/javascript" src="' $cacheWebFile '"></script>'
            
'<link rel="stylesheet" type="text/css" href="' $cacheWebFile '" />'


REPLACE WITH:
PHP Code:

// COMMENT OUT next 3 lines for MaxCDN //
/*        
            $result = ('js' == $type)
            ? '<script type="text/javascript" src="' . $cacheWebFile . '"></script>'
            : '<link rel="stylesheet" type="text/css" href="' . $cacheWebFile . '" />';
*/            
// INSERT for MaxCDN
if ($_SERVER['HTTPS'] != 'on') {
$result = ('js' == $type)
            ? 
'<script type="text/javascript" src="' str_replace("www.domain.com","cdn.domain.com",$cacheWebFile) . '"></script>'
            
'<link rel="stylesheet" type="text/css" href="' str_replace("www.domain.com","cdn.domain.com",$cacheWebFile) . '" />';
} else {
        
$result = ('js' == $type)
            ? 
'<script type="text/javascript" src="' $cacheWebFile '"></script>'
            
'<link rel="stylesheet" type="text/css" href="' $cacheWebFile '" />';
}
// END insert for MaxCDN 


==================================
3. FOR CATEGORY IMAGES

file: /include/templater/plugins/function.get_category_image_url.php

FIND:
Code:

return func_convert_amp(func_get_image_url($category['categoryid'], 'C', $category['image_path']));
REPLACE WITH:
Code:

return str_replace("www.domain.com","cdn.domain.com",func_convert_amp(func_get_image_url($category['categoryid'], 'C', $category['image_path'])));

==================================
4. FOR IMAGES (W, D, P, T images in file system)

file: /include/func/func.files.php

FIND:
Code:

$current_location = $current_location;

REPLACE WITH:
PHP Code:

/** MaxCDN support */
if ($_SERVER['HTTPS'] != 'on') {
$current_location $current_location
} else {
$current_location 'http://cdn.domain.com';
}
/* END MaxCDN support */ 

==================================
5. FOR X-CART BANNER SYSTEM (A images in file system)

FILE:
/skin/common_files/modules/Banner_System/banner_rotator.tpl

FIND:
Code:

src="{$content.image_path|amp}"

REPLACE WITH:
Code:

src="{$content.image_path|amp|replace:'www.domain.com':'cdn.domain.com'}"

ADDED on Jan 18
6. FOR T images -- I think this is needed too

file:
/common_files/product_thumbnail.tpl

FIND:
Code:

{$tmbn_url|amp}
REPLACE WITH:
Code:

{* MaxCDN edit - comment out next line *}
{* {$tmbn_url|amp} *}
{if $smarty.server.HTTPS ne "on"}
{$tmbn_url|amp|replace:'www.domain.com':'cdn.domain.com'}
{else}
{$tmbn_url|amp}
{/if}
{* END MaxCDN edit *}


ADDED on Feb 21
7. FOR IMAGES (W, D, P, T images in file system)

I noticed that some variant images were not getting to the CDN. SO I tried using the code suggested by Phil in post #58 - this seems to work, and is probably a brute force solution. Don't know if I can remove #4?

file: /include/func/func.files.php

FIND:

PHP Code:

// image_path is an locally placed image
            
return $current_location str_replace(XC_DS'/'substr($image_pathstrlen(preg_replace('/' preg_quote(XC_DS'/') . '$/S'''$xcart_dir)))); 


REPLACE WITH:
PHP Code:

// image_path is an locally placed image
            
return 'http://cdn.domain.com' str_replace(XC_DS'/'substr($image_pathstrlen(preg_replace('/' preg_quote(XC_DS'/') . '$/S'''$xcart_dir)))); 


This seems to be doing the trick...

PhilJ 01-18-2013 07:20 AM

Re: MAX cdn
 
Great guide and confirmed working :)

One thing though, for step 4...

Quote:

$current_location = $current_location;

^ Did not exist for me, so I replaced...

Code:

// image_path is an locally placed image
            return $current_location . str_replace(XC_DS, '/', substr($image_path, strlen(preg_replace('/' . preg_quote(XC_DS, '/') . '$/S', '', $xcart_dir))));


With...

Code:

// image_path is an locally placed image
            return 'http://cdn.domain.com' . str_replace(XC_DS, '/', substr($image_path, strlen(preg_replace('/' . preg_quote(XC_DS, '/') . '$/S', '', $xcart_dir))));


(This is for v4.5.4 Gold)

carpeperdiem 01-18-2013 07:37 AM

Re: MAX cdn
 
Quote:

Originally Posted by PhilJ
Great guide and confirmed working :)

For step 4, I had to modify init.php instead of include/func/func.files.php (v4.5.4 Gold)


Phil,

What edit did you make to init.php? I have 4.5.4 gold plus -- I don't think there is a difference in this file??

In your opinion, is it better to do the images (step 4) in init.php (as opposed to /include/func/func.files.php ) ? What is the benefit?

One final step that I failed to discuss: make CERTAIN that you enable robots.txt in the MaxCDN control panel. You do not want duplicate content at the search engines. I believe the crawlers will still find your original images on your site, even if they are all cached to the cdn. Right? Is that how everyone is doing this?

PS -- my page load time is now just over 1.3 seconds (was 4.5 secs+)
To further reduce page load time:

1. CloudSearch needs to use a CDN. I have asked them to do this;
2. Socialize module may be convenient, but it's a resource pig. Too many images, too many http calls. I will work on localizing these resources and getting them to the cdn.
3. Advanced Customer Reviews uses P images on the sidebar, when it only needs a 65px x 65px thumb. I'm working on making this better;
4. I'm sure there are plenty of opportunities to optimize even more, but once we get these elements to the cdn, it's diminishing returns for the effort. A 1 second page load is a zillion times better than 4.5 seconds. hard to take much more off of it.

PhilJ 01-18-2013 07:41 AM

Re: MAX cdn
 
Sorry, init.php was not the correct file to edit, see my modifed post above :)

carpeperdiem 01-18-2013 10:57 AM

Re: MAX cdn
 
I added #6 template edit because T images were not sending to the CDN

Anything else that I should add to this?

PhilJ 01-18-2013 11:03 AM

Re: MAX cdn
 
Quote:

Anything else that I should add to this?

In my case, I also had to take out some IF statements relating to {$current_location}, in order to correctly display the flag icons for the XMultiCurrency module...
Quote:

skin/common_files/modules/XMultiCurrency/customer/complex_selector.tpl

carpeperdiem 02-21-2013 12:54 PM

Re: MAX cdn
 
PLease see post # 57
I added a step #7

http://forum.x-cart.com/showpost.php?p=352228&postcount=57

philrisk 05-01-2013 02:40 AM

Re: MAX cdn
 
I have set up 3 pull zones. One for each of smarty.php, function.load_defer_code.php and func.files.php. Makes a big difference to page load speed. Balances the load across servers then and reduces wait time.

carpeperdiem 05-01-2013 03:24 AM

Re: MAX cdn
 
Quote:

Originally Posted by philrisk
I have set up 3 pull zones. One for each of smarty.php, function.load_defer_code.php and func.files.php. Makes a big difference to page load speed. Balances the load across servers then and reduces wait time.


DO you tell each pull zone to restrict its caching to just those files?
Want to know more on how you configured this. $24/year for 2 more pull zones seems like a bargain if the speed increase is substantial. Please share? Thanks, J

philrisk 05-01-2013 03:33 AM

Re: MAX cdn
 
I have created 3 identical pull zones so you get 3 cdn urls. I used one URL for each of the different lots of content being pulled in. One for the Alt Images, one for the T and P images and one for the css/js plus background images. Seems to work great so far. I haven't done any more restricting that that.

It doesn't cost anything for pull zones. I have the basic 1TB bandwidth from my start-up account and can create as many pull zones as I like. In 6 months I have only used 116Gb bandwidth even though about 5GB is getting downloaded per day.

philrisk 05-01-2013 03:34 AM

Re: MAX cdn
 
If you want to look at my site it is here http://collectables.co.uk

carpeperdiem 05-01-2013 03:42 AM

Re: MAX cdn
 
Quote:

Originally Posted by philrisk
It doesn't cost anything for pull zones.


Are you sure about that? I just tried to add a pull zone and it wanted to charge me $12/year (per zone).

I am only subscribed to the "starter" plan. Could you be subscribed to the "business" plan that includes 25 zones?

philrisk 05-01-2013 04:03 AM

Re: MAX cdn
 
I have the 1Tb pre paid bandwidth. I cant see anything else to tell me the type of account.

philrisk 05-01-2013 04:07 AM

Re: MAX cdn
 
Looking at the plans I am definitely not on the business plan lol.

carpeperdiem 05-01-2013 04:46 AM

Re: MAX cdn
 
Quote:

Originally Posted by philrisk
I have the 1Tb pre paid bandwidth. I cant see anything else to tell me the type of account.


On the pull zones page,
https://cp.maxcdn.com/zones/pull

I can "buy additional zones" -- but not add any (without subscription)
How did you enable 3 unique pull zones?

philrisk 05-01-2013 04:52 AM

Re: MAX cdn
 
Quote:

Originally Posted by carpeperdiem
On the pull zones page,
https://cp.maxcdn.com/zones/pull

I can "buy additional zones" -- but not add any (without subscription)
How did you enable 3 unique pull zones?


I have a button on that page that says "Create Pull Zone" top right. It doesn't charge me to do so.

carpeperdiem 05-01-2013 05:06 AM

Re: MAX cdn
 
This is what I have:

http://www.carpeperdiem.us/xcartforum/maxcdnpullzones.gif

philrisk 05-01-2013 05:10 AM

Re: MAX cdn
 
This is what I have.
http://collectables.co.uk/images/max.jpg

carpeperdiem 05-01-2013 05:25 AM

Re: MAX cdn
 
Are you subscribed to the "Current Package: Starter Recurring" plan? ($39.95)

https://cp.maxcdn.com/account

Hmm... I just sent a support request to maxcdn.

philrisk 05-01-2013 05:35 AM

Re: MAX cdn
 
Quote:

Originally Posted by carpeperdiem
Are you subscribed to the "Current Package: Starter Recurring" plan? ($39.95)

https://cp.maxcdn.com/account

Hmm... I just sent a support request to maxcdn.


I have a $39.95 account according to my first invoice. I did get that first 1TB free with a promotion they were running. That runs till August 2013 when I have to buy more bandwidth for ё39.95(1TB).

The starter plan does say you only get one pull zone included. I know they mess up their advertising campaigns. Maybe that promo put people on the business platform for the starter price. I'm not complaining lol.

carpeperdiem 05-01-2013 06:24 AM

Re: MAX cdn
 
Lucky.
So is it really faster with 3 zones?
I am satisfied with my speed...
Will additional zones speed things up?

http://www.carpeperdiem.us/xcartforum/maxcdn-results1.png

philrisk 05-01-2013 06:37 AM

Re: MAX cdn
 
It sped up my site having 3 zones. 2 even helps. Using Pingdom you could see the wait time decrease with multiple zones.

http://tools.pingdom.com/fpt/#!/h6RkfWa4H/http://collectables.co.uk/

What tool did you use to get those results?

carpeperdiem 05-01-2013 06:40 AM

Re: MAX cdn
 
Quote:

Originally Posted by philrisk
What tool did you use to get those results?


http://www.webpagetest.org/

philrisk 05-01-2013 06:55 AM

Re: MAX cdn
 
Quote:

Originally Posted by carpeperdiem

How long a wait. 3rd in queue for ages!


All times are GMT -8. The time now is 04:27 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.