Plugin ‘Minify’ for Frog CMS

Wednesday, May 20, 2009

Filed under: PHP, web-development — Tags: , , — Dmitri @ 11:25

About Minify

‘Minify’ is a plugin to minify JavaScript and/or CSS code and combine it
into one file on the fly. This will increase performance of website.
So you don’t need to do dozens HTTP request for every JavaScript or CSS file.
Minify plugin is more useful and faster with Funky cache plugin.

Usage

Install the minify plugin to your Frog CMS plugins directory:


$cd /path/to/frog/plugins/
$git clone git://github.com/dknight/minify.git

Activate minify plugin

Set the settings

So next step you need to create ‘cache’ directory in your document root and make it
writable. Due to security settings most webservers doesn’t allow you to create
directories dynamically, so you need to create it manually. Create it in your DOCUMENT_ROOT/cache/ and set writtable permissions.


$mkdir /website/root/cache/
$chmod 0666 /website/root/cache/

Usage in Frog CMS


<?php
$jsFiles = array(
    '/public/javascripts/jquery-1.3.2.min.js',
    '/public/javascripts/jquery.validate.min.js',
    '/public/javascripts/jquery.form.js',
    '/public/javascripts/frog.js'
);
$cssFiles = array(
    'path/to/master.css',
    'path/to/subpage.css',
    'path/to/ie-fix.css'
);

$js_minify  = Minify::factory('js');
$css_minify = Minify::factory('css');
?>

HTML:



...
<link href="<?php echo $css_minify->minify($cssFiles, true); ?>" rel="stylesheet" type="text/css" />
...
<script type="text/javascript" src="<?php echo $js_minify->minify($files, true); ?>"></script>
...

The ‘minify’ method can pass 3 parameters:

name description type default
files File to be minified array [required] array()
output Output to file or raw output into string boolean [optional] false
fileName Name of output file string [optional] ‘min.js’ or ‘min.css’

2 Comments »

  1. По идее надо js и css отдельно подгружать так, что-бы в шапке был css, а внизу после всего содержания – js. Тогда содержание и стиль сразу покажет страницу, а яваскрипт пусть и полумеговый будет подгружаться после этого.

    Comment by Артём Курапов — Tuesday, January 5, 2010 @ 20:58

  2. Артём, да я согласен что CSS сначала надо выводить, а JS в конец. Собственно это уже куда ты это в HTML засунешь от плагина это никак не зависит.

    Comment by Dmitri — Tuesday, January 5, 2010 @ 23:10

RSS feed for comments on this post. TrackBack URL

Leave a comment

© 2008 Dmitri Smirnov