PHP library for generating critical CSS.
Branch: master
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Reverted purging html store, since it would mess with subrequests Mar 2, 2018
.gitignore fixed namespaces Nov 23, 2016
LICENSE Initial commit Nov 23, 2016 Update Feb 21, 2018
composer.json Updated extractor dependency to 1.1 Mar 3, 2018

Critical CSS

PHP library for generating critical CSS.

critical css banner


  • PHP only, no Node.js required.
  • Automatically generated for each page
  • Manual control through {% fold %}{% endfold %} tags
  • Dynamically resolves CSS used on each page

Site(s) using Critical CSS


composer require jandc/critical-css

Register the twig extension and create a wrapper instance with the critical CSS processor
 use TwigWrapper\TwigWrapper;
 use CriticalCssProcessor\CriticalCssProcessor;

 $twigEnvironment->addExtension(new CSSFromHTMLExtractor\Twig\Extension());
 $twigWrapper = new TwigWrapper($twigEnvironment, [new CriticalCssProcessor()]);
Mark the regions of your templates with the provided blocks
{% fold %}
    <div class="my-class">
{% endfold %}
Render your pages, using the twigwrapper
 $twigWrapper->render('@templates/my/template.twig', ['foo'=>'bar']);

Available implementations

If you have your own implementation, please send a pull request to add it to this list.