Widget Accelerator

WidgetAccelerator is the best way to accelerate the displays of your widgets in a webpage.

My blog uses it. It has two accelerated widgets. The display of the page has been increased of more than 10 times actually.

It caches the JS file and prints its content directly in the HTML page. Therefore, your visitors do not need anymore to gather a lot of different javascript files from a lot of various hosts. The main consequence is a speedier website.

It does not check for cache consistency before displaying the page. This is why it is fast (Most HEAD requests are as slow as a GET.)

This is also why you have to specify which widget to cache. Of course you should not use it for widget with highly dynamic content like a Javascript webstat tracker.

Installation
To use this script, you will need to.

  1. Download the script (copy/paste this link and rename the extension of the file to .php)
  2. Upload it to your server.
  3. Create a writable directory to store the cached widgets.
  4. Configure the script: two constants must be defined (at the top of the script). $CACHE_DIR is the path to the cache (ie: $CACHE_DIR="/var/www/cache/";) and $CACHE_TTL is the lifetime in seconds of the cached widget (ie: $CACHE_TTL = 3600;)
  5. Include the script in your template or in the page you want to accelerate: $lt;?php include( "/PATH/TO/widget_accelerator.php" ) ?>
  6. Accelerate the widgets you like. You have to change for instance this widget

    <script defer="defer" id="snap_preview_anywhere" type="text/javascript" src="http://spa.snap.com/snap_preview_anywhere.js?ap=0&etc" ></script>

    to

    <?php accelerate('<script defer="defer" id="snap_preview_anywhere" type="text/javascript" src=http://spa.snap.com/snap_preview_anywhere.js?ap=0&etc" ' ></script>');?>
  7. Optional but nice for me add this quote to your template: powered by WidgetAccelerator
    which in html is: <a href="http://www.deviant-abstraction.net/index.php/2007/01/30/widget-accelerator/"> powered by WidgetAccelerator</a>

A little bit further
WidgetAccelerator looks for src=” or src=’ inside accelerate(). Without proper enclosing of this attribute, the accelerate function will print an error. Finally, all URL inside src must be in absolute to be accelerated.

In case of problem, features ideas or contribution, do not hesitate to mail me or leave a comment here.

Legal
Of course, this script is offered AS IS and I withhold all responsability for any damage that might come due to its use.

Next steps
If you like it, I will add support for images and predictive cache (to automatically set up the cache TTL).

One Response to “Widget Accelerator”

  1. DMY Says:

    Once installed, you can pollute your blog with this
    http://www.widgipedia.com/