View Single Post
  #1  
Old 02-20-2011, 11:12 AM
 
geckoday geckoday is offline
 

X-Wizard
  
Join Date: Aug 2005
Posts: 1,073
 

Default Caching Trustlogo and other third-party js files

A couple of days ago my site wasn't loading due to the Addthis server not responding when my pages were trying to load the Addthis javascript file. This has also happened in the past with the Comodo trustlogo. It really sucks when this happens as you have no control over the other server and you need to hack your site real quick to get the references off your site to get it up and running - once you notice it.

Well, the solution is really pretty simple. Copy the javascript files to your server and load them from there. Doh! Why didn't I do this years ago? But you want to be sure you load the latest version of the javascript file. So setup a cron job to recopy the files every night. Simple and effective.

To do this first add a directory called "cache" in your xcart directory where you will store copies of the js files on your server.

For a Comodo trustlogo you will have something like this in one of your templates:
Code:
<script language="JavaScript" src="https://secure.comodo.net/trustlogo/javascript/trustlogo.js" type="text/javascript"></script>

Before you change this go to your web hosting control panel and setup a cron job to copy the trustlogo.js file to your cache folder once a day using this command:
Code:
wget https://secure.comodo.net/trustlogo/javascript/trustlogo.js -O $HOME/www/cache/trustlogo.js
This command is for typical cpanel hosting with xcart installed in the root of your domain. You might need to adjust the $HOME/www/cache/trustlogo.js depending on what control panel you use, your server configuration and where you have installed xcart. Initially setup the cron to run once a minute until it runs the first time and you have verified that the js file was copied into the cache folder and looks good. Then change the schedule to run once a day.

Now go ahead and change the <script> tag in your template to:
Code:
<script language="JavaScript" src="{$current_location}/cache/trustlogo.js" type="text/javascript"></script>

No more hangs if the Comodo server isn't responding.

I did the same thing for my Hackerproof logo javascript and my Addthis javascript. Now no more scrambling to figure out why my site's not loading and scrambling to rip out a logo or Addthis.
__________________
Manuka Bay Company
X-Cart Version 4.0.19 [Linux]

UGG Boots and other fine sheepskin products
http://www.snowriver.com
Reply With Quote