Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

MAX cdn

 
Reply
   X-Cart forums > X-Cart 4 > Third Party Add-Ons for X-Cart 4
 
Thread Tools
  #51  
Old 01-14-2013, 04:25 PM
 
cellswag cellswag is offline
 

Member
  
Join Date: Jul 2010
Posts: 13
 

Default 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
__________________
Version 4.5.4
Reply With Quote

The following user thanks cellswag for this useful post:
dave01978 (01-15-2013)
  #52  
Old 01-14-2013, 04:40 PM
 
carpeperdiem carpeperdiem is offline
 

X-Guru
  
Join Date: Jul 2006
Location: New York City, USA
Posts: 5,399
 

Default 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.
__________________
xcart 4.5.4 gold+ w/x-payments 1.0.6; xcart gold 4.4.4
Reply With Quote

The following user thanks carpeperdiem for this useful post:
dave01978 (01-15-2013)
  #53  
Old 01-14-2013, 04:51 PM
 
cellswag cellswag is offline
 

Member
  
Join Date: Jul 2010
Posts: 13
 

Default 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?
__________________
Version 4.5.4
Reply With Quote
  #54  
Old 01-15-2013, 08:55 PM
 
dave01978 dave01978 is offline
 

Advanced Member
  
Join Date: Nov 2006
Posts: 95
 

Default 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; } ?>
__________________
Xcart Version 4.5.2
CDSEO Pro
Remember Anonymous carts
Social Bookmarks
Cart Abandonment
catagory map
mobile mod
product map
XCMS
Auth.net DPM
Reply With Quote

The following user thanks dave01978 for this useful post:
carpeperdiem (01-17-2013)
  #55  
Old 01-15-2013, 08:59 PM
 
dave01978 dave01978 is offline
 

Advanced Member
  
Join Date: Nov 2006
Posts: 95
 

Default 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
__________________
Xcart Version 4.5.2
CDSEO Pro
Remember Anonymous carts
Social Bookmarks
Cart Abandonment
catagory map
mobile mod
product map
XCMS
Auth.net DPM
Reply With Quote
  #56  
Old 01-17-2013, 12:40 PM
 
carpeperdiem carpeperdiem is offline
 

X-Guru
  
Join Date: Jul 2006
Location: New York City, USA
Posts: 5,399
 

Default 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
__________________
xcart 4.5.4 gold+ w/x-payments 1.0.6; xcart gold 4.4.4
Reply With Quote
  #57  
Old 01-17-2013, 06:43 PM
 
carpeperdiem carpeperdiem is offline
 

X-Guru
  
Join Date: Jul 2006
Location: New York City, USA
Posts: 5,399
 

Default 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...
__________________
xcart 4.5.4 gold+ w/x-payments 1.0.6; xcart gold 4.4.4
Reply With Quote

The following 5 users thank carpeperdiem for this useful post:
ADDISON (01-17-2013), cflsystems (01-17-2013), DavyMac (05-10-2013), PhilJ (01-18-2013), totaltec (01-18-2013)
  #58  
Old 01-18-2013, 07:20 AM
 
PhilJ PhilJ is offline
 

X-Guru
  
Join Date: Nov 2002
Posts: 4,094
 

Default 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)
__________________
xcartmods.co.uk
Reply With Quote

The following user thanks PhilJ for this useful post:
carpeperdiem (02-21-2013)
  #59  
Old 01-18-2013, 07:37 AM
 
carpeperdiem carpeperdiem is offline
 

X-Guru
  
Join Date: Jul 2006
Location: New York City, USA
Posts: 5,399
 

Default 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.
__________________
xcart 4.5.4 gold+ w/x-payments 1.0.6; xcart gold 4.4.4
Reply With Quote
  #60  
Old 01-18-2013, 07:41 AM
 
PhilJ PhilJ is offline
 

X-Guru
  
Join Date: Nov 2002
Posts: 4,094
 

Default Re: MAX cdn

Sorry, init.php was not the correct file to edit, see my modifed post above
__________________
xcartmods.co.uk
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Third Party Add-Ons for X-Cart 4



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 06:57 AM.

   

 
X-Cart forums © 2001-2020