PHPackages                             burtwraynolds/critical-css - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. burtwraynolds/critical-css

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

burtwraynolds/critical-css
==========================

A Laravel package for generating and using inline critical-path CSS.

1.0(5y ago)1101[13 PRs](https://github.com/brettwray/CriticalCss/pulls)MITPHPPHP &gt;=7.0

Since Jul 7Pushed 3y ago1 watchersCompare

[ Source](https://github.com/brettwray/CriticalCss)[ Packagist](https://packagist.org/packages/burtwraynolds/critical-css)[ RSS](/packages/burtwraynolds-critical-css/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (10)Versions (15)Used By (0)

This is a forked package from [kalfheim/critical-css](https://github.com/kalfheim/critical-css) which was not maintained and not updated for laravel 7.
=======================================================================================================================================================

[](#this-is-a-forked-package-from-kalfheimcritical-css-which-was-not-maintained-and-not-updated-for-laravel-7)

This package is experimental and may not be maintained. Use at your own risk.
-----------------------------------------------------------------------------

[](#this-package-is-experimental-and-may-not-be-maintained-use-at-your-own-risk)

A Laravel package for generating and using inline critical-path CSS.

[![CriticalCss](https://camo.githubusercontent.com/ea34679fbc65375264a06e10ca61072d65626fe5e6aec80c9c83126bfe823698/68747470733a2f2f692e696d6775722e636f6d2f5a49476774417a2e676966)](https://camo.githubusercontent.com/ea34679fbc65375264a06e10ca61072d65626fe5e6aec80c9c83126bfe823698/68747470733a2f2f692e696d6775722e636f6d2f5a49476774417a2e676966)

Why?
----

[](#why)

> For best performance, you may want to consider inlining the critical CSS directly into the HTML document. This eliminates additional roundtrips in the critical path and if done correctly can be used to deliver a “one roundtrip” critical path length where only the HTML is a blocking resource.

More information:

-

**Table of Contents**

- [Installation](#installation)
    - [1) Install the Critical npm package](#1-install-the-critical-npm-package)
    - [2) Require the package](#2-require-the-package)
    - [3) Configure Laravel](#3-configure-laravel)
- [Usage](#usage)
    - [Generating critical-path CSS](#generating-critical-path-css)
    - [Using critical-path CSS with Blade templates](#using-critical-path-css-with-blade-templates)
- [A demo](#a-demo)
    - [PageSpeed Insights results](#pagespeed-insights-results)
- [A note on Laravel 5.0 compatibility](#a-note-on-laravel-50-compatibility)

Installation
------------

[](#installation)

### 1) Install the Critical npm package

[](#1-install-the-critical-npm-package)

This package is used to extract critical-path CSS from an HTML document.

From your project's base path, run:

```
$ npm install critical --save

```

Alternatively, install it globally:

```
$ npm install -g critical

```

### 2) Require the package

[](#2-require-the-package)

Next, you'll need to require the package using Composer:

From your project's base path, run:

```
$ composer require burtwraynolds/critical-css

```

### 3) Configure Laravel

[](#3-configure-laravel)

#### Service Provider

[](#service-provider)

Add the following to the `providers` key in `config/app.php`:

```
'providers' => [
    burtwraynolds\CriticalCss\CriticalCssServiceProvider::class,
];
```

#### Console

[](#console)

To get access to the `criticalcss:clear` and `criticalcss:make` commands, add the following to the `$commands` property in `app/Console/Kernel.php`:

```
protected $commands = [
    \burtwraynolds\CriticalCss\Console\CriticalCssMake::class,
    \burtwraynolds\CriticalCss\Console\CriticalCssClear::class,
];
```

#### Config

[](#config)

Generate a template for the `config/criticalcss.php` file by running:

```
$ php artisan vendor:publish

```

> **Note:** Descriptions for the config options are only present in the config file, **not** in this readme. Click [here](https://github.com/brettwray/critical-css/blob/master/src/config/criticalcss.php) to open the config file on GitHub.

Usage
-----

[](#usage)

Before getting started, I highly recommend reading through the [`config/criticalcss.php`](src/config/criticalcss.php) file. That will give you a good idea of how this all works.

### Generating critical-path CSS

[](#generating-critical-path-css)

Providing everything is set up and configured properly, all you need to do in order to generate a fresh set of critical-path CSS files, is running the following command:

```
$ php artisan criticalcss:make

```

This will generate a unique file for each of the URIs (routes) provided.

See [this commit](https://github.com/brettwray/critical-css-demo/commit/8288ba8971fc7381ef933affdde3b3d71c5475e3) for a diff of the implementation.

### Using critical-path CSS with Blade templates

[](#using-critical-path-css-with-blade-templates)

The service provider provides a new Blade directive named `@criticalCss`.

Simply call that directive, passing a route as the only argument, like so:

```

  ...
  @criticalCss('some/route')

```

If no argument is passed, the current route will be used, however, I highly recommend always passing a specific route.

And of course, make sure to asynchronously load the full CSS for the page using something like loadCSS ().

Full example (using Elixir to generate the URL for the CSS file, which or course is optional):

```

  ...
  @criticalCss('some/route')

    !function(a){"use strict";var b=function(b,c,d){var g,e=a.document,f=e.createElement("link");if(c)g=c;else{var h=(e.body||e.getElementsByTagName("head")[0]).childNodes;g=h[h.length-1]}var i=e.styleSheets;f.rel="stylesheet",f.href=b,f.media="only x",g.parentNode.insertBefore(f,c?g:g.nextSibling);var j=function(a){for(var b=f.href,c=i.length;c--;)if(i[c].href===b)return a();setTimeout(function(){j(a)})};return f.onloadcssdefined=j,j(function(){f.media=d||"all"}),f};"undefined"!=typeof module?module.exports=b:a.loadCSS=b}("undefined"!=typeof global?global:this);
    loadCSS('{{ elixir('css/app.css') }}');

```

For multiple views, you may wrap `@criticalCss` in a `@section`, then `@yield` the section in a master view.

A note on Laravel 5.0 compatibility
-----------------------------------

[](#a-note-on-laravel-50-compatibility)

On Laravel 5.0, you must set `'blade_directive' => false` in the config. This is **not** recommended, but because [Custom Directives](http://laravel.com/docs/5.1/blade#extending-blade) were introduced in 5.1, it has to be done.

This will require adding the following to the `aliases` key in **config/app.php**:

```
'aliases' => [
    'Critical' => burtwraynolds\CriticalCss\Facades\Critical::class,
];
```

In your Blade views, you'll now be able to do the following instead of `@criticalCss('some/route')`:

```
{!! Critical::css('some/route') !!}
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2133d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/553873c8e4ff76e62f56f4304d49a10659429ae3f477aa3a53ce0fe80250d906?d=identicon)[burtwraynolds](/maintainers/burtwraynolds)

---

Top Contributors

[![brettwray](https://avatars.githubusercontent.com/u/13531627?v=4)](https://github.com/brettwray "brettwray (5 commits)")

---

Tags

laravelcssperformance

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/burtwraynolds-critical-css/health.svg)

```
[![Health](https://phpackages.com/badges/burtwraynolds-critical-css/health.svg)](https://phpackages.com/packages/burtwraynolds-critical-css)
```

###  Alternatives

[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.5k25.9M107](/packages/laravel-cashier)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k12.1M99](/packages/laravel-pulse)[akaunting/laravel-money

Currency formatting and conversion package for Laravel

7825.3M18](/packages/akaunting-laravel-money)[spatie/laravel-enum

Laravel Enum support

3655.4M31](/packages/spatie-laravel-enum)[psalm/plugin-laravel

Psalm plugin for Laravel

3274.9M308](/packages/psalm-plugin-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
