Skip to content

JanDC/critical-css

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 

Critical CSS

PHP library for generating critical CSS.

critical css banner

Features

  • 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

Installation

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">
    ...
    </div>
{% 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.

About

PHP library for generating critical CSS.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages