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.
Note: Complete documentation is available in the project download.
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:
- An object implementing the VP_Module interface
- A 'group' to place this object into
This class is NOT compatible with PHP 4.
- //include requied classes
- //create the new Vanishing Point object
- $vp = new VanishingPoint();
- //add a module of type VP_JS to the group 'example' with version 1-0-0
- $vp->addModule(new VP_JS("example.js","1-0-0"),"example");
- $output = $vp->render("example");
- echo $output['example'];
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.
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.