drupaljedi / css-tree-shaking
Helps you to eliminate the portions of CSS you aren't using. Usually should be used to generate AMP pages, where is the fixed limit for maximum styles size.
Installs: 20 644
Dependents: 0
Suggesters: 0
Security: 0
Stars: 12
Watchers: 4
Forks: 2
Open Issues: 2
Requires
- php: >=7.0
- ext-dom: *
- sabberworm/php-css-parser: ^8.2
- symfony/css-selector: ^3
- symfony/dom-crawler: ~3.0|~4.0
Requires (Dev)
- phpunit/phpunit: ^6
This package is auto-updated.
Last update: 2024-11-15 04:30:00 UTC
README
Helps you to eliminate the portions of CSS you aren't using. Usually should be used to generate AMP pages, where is the fixed limit for maximum styles size.
Installation
composer require drupaljedi/css-tree-shaking
Usage
Pretty simple to use, just create the object and shake it :)
<?php include 'vendor/autoload.php'; use DrupalJedi\CssTreeShaking; $cssShaker = new CssTreeShaking($html); $optimizedHtml = $cssShaker->shakeIt();
Where $html
is raw HTML with inliny styles.
By default, styles will be shaken only if the limit (50kb) is exceeded.
If you want to shake the styles in any case, just call the shakeIt()
with a TRUE
argument:
$optimizedHtml = $cssShaker->shakeIt(TRUE);
Features
- PSR-4 autoloading compliant structure
- Easy to use to any framework or even a plain php file