2017 © Pedro Peláez
 

library css-optimizer

CSS Optimizer - Minifies stylesheets by removing duplicates and combining selectors

image

lastzero/css-optimizer

CSS Optimizer - Minifies stylesheets by removing duplicates and combining selectors

  • Tuesday, December 1, 2015
  • by lastzero
  • Repository
  • 1 Watchers
  • 1 Stars
  • 148 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 2 Versions
  • 1 % Grown

The README.md

CSS Optimizer for PHP

Build Status Latest Stable Version License, (*1)

Minifies stylesheets by removing duplicates and combining selectors - mostly safe and very efficient. This package was developed as a "quick win" to optimize the CSS of an existing commercial Web site, as the CSS contained many duplicates and similar selectors created by a CSS precompiler. It was published in the hope to help others in the same situation., (*2)

Note: The optimization is performed using simple (and fast) string functions - it's not a real CSS parser. It requires well formed CSS without inline comments (don't worry, you can use the minifyCss() method for that, see usage)., (*3)

Warning: The order of selectors in your CSS does play a role and the "further down" one does in fact win when the specificity values are exactly the same. If your CSS relies on order to work, this optimization will obviously break it. See also https://en.wikipedia.org/wiki/Cascading_Style_Sheets#Specificity, (*4)

Input:, (*5)

body { foo:bar; too: me; } 
body { baz:foo; }
body { foo: new }
div.test { border: 1px solid black; }
div.other { border: 1px solid black}

Output:, (*6)

body{baz:foo;foo:new;too:me}div.other,div.test{border:1px solid black}

Usage:, (*7)

$optimizer = new \CssOptimizer\Css\Optimizer;

$inputCss = 'body { foo:bar; too: me;} body { baz:foo; } body { foo: new }
div.test { border: 1px solid black; }
div.other { border: 1px solid black} ';

$minifiedCss = $optimizer->minifyCss($inputCss);
$optimizedCss = $optimizer->optimizeCss($minifiedCss);

print_r($optimizer->getCounts());

Assetic filter

This library comes with a ready-to-use Assetic filter (for Symfony2). Please use a pre-filter like CssMinFilter., (*8)

Usage:, (*9)

$filter = new \CssOptimizer\Assetic\Filter\CssOptimizeFilter;
$asset = new StringAsset($inputCss);
$asset->ensureFilter($filter);
$outputCss = $asset->dump();

Composer

If you are using composer, simply add "lastzero/css-optimizer" to your composer.json file and run composer update:, (*10)

"require": {
    "lastzero/css-optimizer": "*"
}

The Versions

01/12 2015

dev-master

9999999-dev https://github.com/lastzero/css-optimizer

CSS Optimizer - Minifies stylesheets by removing duplicates and combining selectors

  Sources   Download

MIT

The Requires

 

The Development Requires

css symfony optimization assetic minification

25/11 2015

v1.0.0

1.0.0.0 https://github.com/lastzero/css-optimizer

CSS Optimizer - Minifies stylesheets by removing duplicates and combining selectors

  Sources   Download

MIT

The Requires

 

The Development Requires

css symfony optimization assetic minification