Vanishing Point

Overview

Vanishing Point is an open-source PHP package designed to help automate the optimization of web content. The framework class, class.VanishingPoint.php enables the developer to implement plugins for different file types to be optimized. In other words, Vanishing Point doesn't do any of the work, but it provides the management functionality necessary for the system.

The framework class accepts plugins as implementations of the VP_Module interface located in class.VP_Module.php. The interface defines what functions must be defined and how they should interact with Vanishing Point. Where Vanishing Point manages the plugins, the plugins manage the files to be optimized.

So far, two plugins have been developed for Vanishing Point. One for Javascript and one for CSS.

Note: Complete documentation is available in the project download.

class.VanishingPoint.php

Vanishing Point is a framework that enables the programmer to implement plugins for different file types to be optimized. The class's main role in optimization is managing the files and calling the appropriate render(). Plugins are based upon the VP_Module interface and should adhere to the standards defined in the VP_Module documentation.

Vanishing Point accepts files through addModule() which takes:

  1. An object implementing the VP_Module interface
  2. A 'group' to place this object into

These 'groups' allow logical groupings of files to be designated. For example, a javascript group may be defined to deal with all AJAX requests. Mixed with render()'s ability to output only selected 'groups', the programmer can logically build dependencies and output the AJAX javascript includes only when AJAX is going to be required.

This class is NOT compatible with PHP 4.

The following is an example of using Vanishing Point. For the sake of demonstration, we have used the VP_JS Javascript Plugin for Vanishing Point (VP_JS Javascript Plugin)

  1. <?php
  2. //include requied classes
  3. require_once('class.VanishingPoint.php');
  4. require_once('class.VP_JS.php');
  5.  
  6. //create the new Vanishing Point object
  7. $vp = new VanishingPoint();
  8.  
  9. //add a module of type VP_JS to the group 'example' with version 1-0-0
  10. $vp->addModule(new VP_JS("example.js","1-0-0"),"example");
  11.  
  12. $output = $vp->render("example");
  13. echo $output['example'];
  14.  
  15. ?>

class.VP_Module.php

VP_Module is an interface to be implemented by all Vanishing Point plugins. The interface defines what functions MUST be defined and how they should interact with Vanishing Point.

All necessary data should be passed to Vanishing Point plugins via their constructor.

To create a new Vanishing Point plugin all 4 interface functions and a constructor must be defined. If a particular function is not going to be implemented, for example combine(), it must still be declared within the context of the plugin, however; it's function body can be left empty.

getFileName() must be created and must return the unaltered string containing the filename. Failure to do so will result in duplication of files by Vanishing Point. With getFileName() as the exception, all functions may be defined as desired as long as the function structure (parameters and return values) do not deviate.

VP_JS: Javascript Plugin Overview

The methodology employed in the Javascript plugin was heavily influenced by the Vitamin article, Serving Javascript Fast by Cal Henderson.

The plugin performs two main functions: packing and combining. Packing files removes unecessary white space as well as comments to reduce the file size as much as possible. By then defining groups of scripts that are always loaded together we can combine packed files into one or a few files to be served, thus minimizing the largest cause of load delay, HTTP requests.

VP_CSS: CSS Plugin Overview

It is convenient for designers to maintain several (if not many) separate style sheets for any given site. Whether these are included in different link tags at the top of the html or inside the main style sheet, the result is the same: multiple HTTP requests.

The CSS plugin will use a combination configuration or follow "@include" and combine all the referenced style sheets into one monolithic sheet as well as minify the contents to remove excess whitespace and comments.

Site Info

Contact Us

By Phone:
979-696-SITE (7483)
By Email:
Send Email
For Support:
Please visit our Get Satisfaction forum.

About Us

The Kitchen is run by the fine folk at Net Perspective, LLC.

Find out more about The Kitchen or visit us at Net-Perspective.com.

Copyright

This site, its contents, and its design are © Copyright 2008 - 2017 Net Perspective, LLC. All rights reserved.

Some images used here by permission are copyright of their respective owners. Thanks to Mark James for the fantastic Silk icon set.