Changes between Initial Version and Version 1 of WikiStart

Show
Ignore:
Timestamp:
11/06/09 21:33:09 (10 months ago)
Author:
andy
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • WikiStart

    v1 v1  
     1Webtatic Optimizer is a program which will optimise your website’s static files, allowing your website to reduce the number of requests and bandwidth used. 
     2 
     3== Requirements == 
     4 
     5PHP >= 5.2 
     6 
     7== Download == 
     8 
     9[http://www.webtatic.com/files/WebtaticOptimizer-1.0.0-beta1.tgz WebtaticOptimizer-1.0.0-beta1.tgz] 
     10 
     11 
     12== Installation == 
     13 
     14{{{ 
     15#!sh 
     16wget http://www.webtatic.com/files/WebtaticOptimizer-1.0.0-beta1.tgz 
     17tar xvf WebtaticOptimizer-1.0.0-beta1.tgz -C /usr/local/lib 
     18ln -s /usr/local/lib/WebtaticOptimizer-1.0.0-beta1/bin/optimizer-compile.php /usr/local/bin/optimizer-compile 
     19}}} 
     20 
     21== Usage == 
     22 
     23{{{ 
     24Usage: optimizer-compile [options] FILES 
     25Compile using the config FILES specifed 
     26 
     27Options: 
     28  -h, --help             display this message 
     29  -s, --section SECTION  select the SECTION section from the config 
     30  -o, --option OPTION    select the OPTION subset from the config 
     31  -t, --type TYPE        set the config type to TYPE [default: auto] 
     32      --auto             automatically select the config type by extension 
     33      --ini              set the config type to ini 
     34      --php              set the config type to php 
     35      --xml              set the config type to xml 
     36}}} 
     37 
     38== Development == 
     39The development version of the program can be accessed from a read-only Subversion repository. 
     40 
     41{{{ 
     42#!sh 
     43svn checkout http://svn.webtatic.com/optimizer/trunk /path/to/optimizer/ 
     44}}} 
     45 
     46== Example == 
     47 
     48Store the following in /path/to/project/optimizer.ini 
     49 
     50{{{ 
     51[config] 
     52version = 1.0.0 
     53workingPath = . 
     54 
     55[css] 
     56defaults.output = site.css 
     57files = " 
     58        + css/**.css 
     59" 
     60}}} 
     61 
     62Create a css file /path/to/project/css/layout.css: 
     63 
     64{{{ 
     65body { 
     66        font-size: 12px; 
     67} 
     68}}} 
     69 
     70Run: 
     71{{{ 
     72#!sh 
     73optimizer-compile /path/to/project/optimizer.ini 
     74}}} 
     75 
     76Now there will be a /path/to/project/site.css and site.css.gz which can be loaded by your html. 
     77 
     78== Configuration == 
     79 
     80The configuration consists of a [config] section which defines the environment and what plugins to load, a [default] section which is applied to all other sections, and custom sections. 
     81 
     82=== [config] section === 
     83 
     84Here you define the version of your config, any plugins to load, and the working path from which your files exist, e.g. 
     85 
     86{{{ 
     87[config] 
     88version = 1.0.0 
     89plugins = autoMatch, filter, file, gzip 
     90workingPath = http 
     91}}} 
     92 
     93=== Custom sections === 
     94 
     95Custom sections define various different configurations to be applied to different types of files, e.g. you could have a javascript and a css section. 
     96 
     97One parameter must exist, “files”, which declares files to include or exclude from that section, e.g. the following section will only deal with javascript files in http/includes/js/ excluding my-exclude.js: 
     98 
     99{{{ 
     100[javascript] 
     101files = " 
     102  + http/includes/js/**.js 
     103  - http/includes/js/my-exclude.js 
     104" 
     105}}} 
     106 
     107 * + indicates files matching the following pattern should be included 
     108 * - indicates files matching the following pattern should be excluded 
     109 * one * indicates to match any file with a pattern only in the current directory 
     110 * two * indicates to recursively match any file with the pattern 
     111 
     112=== File parameters === 
     113 
     114For each file that is matched, various parameters are assigned to it, which can be used by plugins. To add parameters, you can define them in a default.keyname = value syntax, or use matches from the input filename. E.g. for the following structure: 
     115 
     116 * http/includes/javascript/file1.js 
     117 * http/includes/javascript/file2.js 
     118 
     119The following configuration will assign the parameter “output” the value “http/includes/site.js”, the parameter “package” the values “file1″ and “file2″ for each file respectively, and the parameter “filename” with the full path to each file: 
     120 
     121{{{ 
     122[javascript] 
     123defaults.output = http/includes/site.js 
     124files = " 
     125  + http/includes/javascript/:package.js 
     126" 
     127}}} 
     128 
     129== Plugins == 
     130 
     131It is built up from PHP classes, which plug into the core. To enable plugins, define them in the [config] section. The order of the plugins is important, as they will be run in order. E.g. filter must come before file and gzip otherwise nothing will be done to the output. 
     132 
     133{{{ 
     134[config] 
     135plugins = autoMatch, filter, file, gzip 
     136}}} 
     137 
     138The plugins are: 
     139 
     140 AutoMatch 
     141   A helper plugin which adds settings from the configuration based on file matches. 
     142 File 
     143   A plugin that concatenates and stores the contents of input files into output files. 
     144 Filter 
     145   A plugin that filters the contents of input files and passes the result onto the next plugin. 
     146 Gzip 
     147   A plugin, like File, but Gzips the contents of the output files. 
     148 
     149=== AutoMatch === 
     150 
     151AutoMatch will match any input file that has a parameter matched with a PREG expression, and add its defined defaults to that file’s parameters. 
     152 
     153Default AutoMatch configuration comes with the optimizer to perform the best combination of filters to css and javascript files, however you can define additional configurations. E.g. this will add configuration to minify any input matches that have a jquery-style filename: 
     154 
     155{{{ 
     156[config] 
     157autoMatch.jQuery.match.filename = "#/jquery\..*?\.js$" 
     158autoMatch.jQuery.defaults.filters = jsmin 
     159}}} 
     160 
     161=== File === 
     162 
     163This will save to file any input files, which have an “output” parameter, to the output file location. You can specify the output file in your config section. E.g. the following will concatenate all css files and store in http/includes/site.css 
     164 
     165{{{ 
     166[css] 
     167defaults.output = http/includes/site.css 
     168files = " 
     169  + http/includes/css/**.css 
     170" 
     171}}} 
     172 
     173You can also use an input file’s parameters in the output filename, e.g. the following will, for each subdirectory of the javascript folder, concatenate all javascript files, and store in seperate files per subdirectory. 
     174 
     175{{{ 
     176[javascript] 
     177defaults.output = http/includes/:package.js 
     178files = " 
     179   + http/includes/javascript/:package/**.js 
     180" 
     181}}} 
     182 
     183=== Filter === 
     184 
     185The Filter plugin can perform the following filters: 
     186 
     187 Cssmin 
     188   Minify css file content, removing whitespaces and comments 
     189 CssUrlModified 
     190   Adds ?modifed-timestamp onto urls in css url()'s. This allows you to additionally turn on aggressive http expiry times, whilst user agents will still get fresh images back when a file is modified. 
     191 Jsmin 
     192   Minifies javascript file content using the PHP port of Jsmin. 
     193 
     194E.g. to specify filters add the following to your config section: 
     195 
     196{{{ 
     197[section] 
     198defaults.filters = cssUrlModified, cssmin 
     199}}} 
     200 
     201=== Gzip === 
     202 
     203Gzip acts almost identically to the File plugin, except it will read the “gzip” parameter for the output location. By default, this is the "output" parameter concatenated with ".gz" 
     204 
     205Together with a configuration, these can be used to concatenate css and javascript files and minify them as applicable, and store them in uncompressed and compressed files for serving via the web.