Month: January 2012

CSS File Merger and Minifier

I am happy to announce that I have just finished a new tool that you may find useful. Builder.CSS merges and minifies style sheets into a single file and thus reduces HTTP requests and file download time.

Features:

  • Easily configurable list of files that need to be merged.
  • Minification options:
    • Remove line-breaks and tabs;
    • Remove extra white-space;
    • Remove comments;
    • Remove comments;
  • Two types for saving the output code – as a physical file or as a copy-paste string.

Requirements:

  • Latest version of Mozilla FireFox, Google Chrome, Apple Safari, Opera or Internet Explorer.
  • Web-server with PHP.
  • JavaScript should be enabled.

Screenshots:

Download directly from this link and enjoy! If you are looking for a JavaScript minifier and merger, you can try Builder.JS.

Advertisements

Maintainable CSS3 Preprocessor and Generator for PHP

If you are looking for a complete CSS merging and minification tool, check Builder.CSS, otherwise, keep reading this post :)

Here is a small script written in PHP for rendering of vendor-specific CSS3 properties on the fly, by defining them just once using the official W3C syntax. The css3 function generates not only vendor-specific properties, such as -moz-user-select, but also vendor-specific property values like the various CSS3 functions such as calc(), element(), linear- and radial-gradient(). You can download it from this link.

Below is an example for defining a vendor-specific property:

div
{
<? css3('transition', 'opacity 200ms linear'); ?>
}

… Which will output:

div
{
-moz-transition: opacity 200ms linear;
-webkit-transition: opacity 200ms linear;
-o-transition: opacity 200ms linear;
-ms-transition: opacity 200ms linear;
transition: opacity 200ms linear;
}

And here’s an example for defining the CSS3 function element():

div
{
<? css3('background', 'element(#background-div)'); ?>
}

… Which will give you:

div
{
background: -moz-element(#background-div);
background: -webkit-element(#background-div);
background: -o-element(#background-div);
background: -ms-element(#background-div);
background: element(#background-div);
}

* As of January 2012, the element() function is supported only by Mozilla FireFox, so you may consider using normal CSS to define that function.

All Features:

  • Detects and renders both vendor-specific properties and vendor-specific values, such as CSS3 functions;
  • Combines multiple CSS files into one;
  • If GZIP is available, the output stylesheet is gzipped and its size is much smaller than the size of all CSS files;
  • Supports multiple CSS3 property values, such as:
    div
    {
    <? css3('background', 'url("background.png") no-repeat center, linear-gradient(#ccc, #333)'); ?>
    }
    

Requirements:

  • Web-server with PHP support;

Usage:

  1. Register the script the way you normally register style sheets on the page:
    <link rel="stylesheet" href="css3.php?files=" />
    
  2. In the files parameter, define the path to all of the stylesheets that you want to merge:
    <link rel="stylesheet" href="css3.php?files=Styles/styles-01.css,Styles/styles-02.css" />
    

    The order in which you define them is going to be their inclusion order in the final PHP-processed file. Make sure that URLs, pointing to external assets such as background images and fonts are set relatively to the css3.php file, otherwise, they will not be requested correctly.

  3. In each of the CSS files, use the css3($property, $value) function to define CSS3 properties:
    div
    {
    <? css3('background', 'element(#background-div)'); ?>
    }
    
  4. If you wish to exclude some specific vendor properties, you can just remove them from the $prefixes array in the css3.php file:
    $prefixes = array('-moz-', '-webkit-', '-o-', '-ms-');
    

    The script can be easily changed to allow passing of prefixes as a function argument, if you wish to define the properties per function usage. Even better – the third argument can be an exclusion array, which will be checked against the vendor-specific array in the script itself (in_array()). Basically, you can change the function to this:

    div
    {
    <? css3('background', 'element(#background-div)', array('-moz-', '-webkit-')); ?>
    }
    
  5. Is is recommended to extend the script so it checks for already existing processed file on the server, instead of processing and merging it each time the page is requested. If the file does not exist, then the result of the PHP processing can be output to a static file that will be served.

The script can be downloaded from here. Other cool HTML5, CSS3 and JavaScript experiments can be found on this page.

2011 in Review

The WordPress.com stats helper monkeys prepared a 2011 annual report for this blog.

Here’s an excerpt:

The Louvre Museum has 8.5 million visitors per year. This blog was viewed about 180,000 times in 2011. If it were an exhibit at the Louvre Museum, it would take about 8 days for that many people to see it.

Click here to see the complete report.