Skip to content

About

A critical CSS parser for PHP, which can isolate CSS style blocks containing a !critical comment

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

8 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP Critical CSS

A PHP class that uses sabberworm/php-css-parser to parse a CSS file, extracting any selector blocks which contain a CSS /* !critical */ comment - outputting them as separate files.

Named annotations such as /* !critical:services-grid */ are written to a separate conditional bundle. For an input named styles.css, that example produces styles-critical-services-grid.css.

For an example of the CSS comment please see test/test.css.

Installation

composer require richmilns/php-critical-css

Usage

Command Line Interface

$ vendor/bin/critical-css path/to/my/file.css

PHP

use Exception;
use CriticalCSS\Parser;

require_once 'vendor/autoload.php';

try {
    $critical = new Parser('path/to/my/file.css');
    $critical->parse()->output('compact');
    // saves two standard files:
    // - path/to/my/file-critical.css
    // - path/to/my/file-non-critical.css
    // and one file per named annotation, for example:
    // - path/to/my/file-critical-services-grid.css
} catch(Exception $exception) {
    ray($exception->getMessage());
}

About

A critical CSS parser for PHP, which can isolate CSS style blocks containing a !critical comment

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages