PHPackages                             angus-mcritchie/blade-boost-directive - 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. [Templating &amp; Views](/categories/templating)
4. /
5. angus-mcritchie/blade-boost-directive

ActiveLibrary[Templating &amp; Views](/categories/templating)

angus-mcritchie/blade-boost-directive
=====================================

Lightning-Fast Blade Components with `@boost` Directive

v1.2.0(2mo ago)3910.0k—3.1%1[1 PRs](https://github.com/angus-mcritchie/blade-boost-directive/pulls)MITPHPPHP ^8.1CI passing

Since Mar 29Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/angus-mcritchie/blade-boost-directive)[ Packagist](https://packagist.org/packages/angus-mcritchie/blade-boost-directive)[ Docs](https://github.com/angus-mcritchie/blade-boost-directive)[ GitHub Sponsors]()[ RSS](/packages/angus-mcritchie-blade-boost-directive/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (12)Versions (16)Used By (0)

Lightning-Fast Blade Components with `@boost`
=============================================

[](#lightning-fast-blade-components-with-boost)

[![Latest Version on Packagist](https://camo.githubusercontent.com/8a12f43bb7ea0d285fe40a3c6511272931e83f2ff0169b2674bd343da284a000/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616e6775732d6d63726974636869652f626c6164652d626f6f73742d6469726563746976652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/angus-mcritchie/blade-boost-directive)[![GitHub Tests Action Status](https://camo.githubusercontent.com/9a67aec0636cf94a9d5f0d02a93bfdb5c7ac186794779cbd0137be8edd88f46b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f616e6775732d6d63726974636869652f626c6164652d626f6f73742d6469726563746976652f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/angus-mcritchie/blade-boost-directive/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/8759931ba1d5265f072f54c57e3ecf0904038e92244c4fb10d940ec7b1a5308f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f616e6775732d6d63726974636869652f626c6164652d626f6f73742d6469726563746976652f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/angus-mcritchie/blade-boost-directive/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/b9b0d6400ae29b1b2e847a00e99399cc16adb5b65f83d24701416bd85a46579d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616e6775732d6d63726974636869652f626c6164652d626f6f73742d6469726563746976652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/angus-mcritchie/blade-boost-directive)

Adds a `@boost` Blade directive to your Laravel application. Caches the HTML rendered from Blade code. Optionally you can perform a simple [`str_replace`](https://www.php.net/manual/en/function.str-replace.php) for any variables passed to the directive.

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Signature](#signature)
- [Parameters](#parameters)
- [Usage](#usage)
    - [Repeating Code Use Case](#repeating-code-use-case)
    - [But I Have an `if` Statment in There!](#but-i-have-an-if-statement-in-there)
    - [Large Component Use Case](#large-component-use-case)
    - [Simple Small Repeating Use Case](#simple-small-repeating-use-case)
- [Escaping](#escaping)
- [Cache Store](#cache-store)
- [Configuration](#configuration)
- [Benchmarks](#benchmarks)
- [Testing](#testing)
- [Changelog](#changelog)
- [Contributing](#contributing)
- [Security Vulnerabilities](#security-vulnerabilities)
- [Credits](#credits)
- [License](#license)

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

[](#installation)

You can install the package via composer:

```
composer require angus-mcritchie/blade-boost-directive
```

Signature
---------

[](#signature)

```
@boost(string|array $key, array $options = [])

@endboost

@boost(array $options = [])

@endboost
```

Parameters
----------

[](#parameters)

```
$key: string|array // Required, arrays will be joined with a "."
$options: [
    'key': string|array, // see above (required)
    'store': string, // The cache store to use (default: array)
    'raw': bool, // Whether to escape the HTML or not (default: false)
    'replace': [ // Variables to replace in the HTML (optional)
        '{foo}' => 'bar'
    ],
];

```

Usage
-----

[](#usage)

The `@boost` directive can be used to wrap any Blade code. It will render the blade code once and cache the HTML and can optionally replace any variables passed to the directive via the second argument.

### Repeating Code Use Case

[](#repeating-code-use-case)

A common use case would be that you're rendering a page of `` components which looks like this:

```
@foreach($posts as $post)

            {{ $post->title }}
            {{ $post->description }}

        {{ $post->author }}

                Read More

@endforeach
```

That is a total of 9 components per post, if we have 30 per page, that is 270 components in total and there are only 4 variables for the whole card.

Let's see how we can use the `@boost` directive to speed this up.

```
@foreach($posts as $post)
    @boost([
        'key' => 'post-card',
        'replace' => [
            '{title}' => $post->title,
            '{name}' => $post->name,
            '{url}' => route('post.show', $post),
            '{image}' => $post->image,
            '{author}' => $post->author,
            '{description}' => $post->description
        ]
    ])

                {title}
                {description}

            {author}

                    Read More

    @endboost
@endforeach
```

Wrapping the whole component in the `@boost` directive will store the HTML in the cache, then replace the passed variables with the values from the `$post` object and results in Blade only rendering **1 component instead of 270** 🚀.

You could use the `file` cache store and render zero components (after the first request) but you'll need to clear the cache when you make changes to the component.

### But I Have an `if` Statement in There!

[](#but-i-have-an-if-statement-in-there)

If you want to conditionally show the badge, you'll want to update the key to include the condition so that the cache is different for each condition.

Passing the key as an array with all your conditions, `@boost` will join the array with a `.` and use that as the cache key.

```
@foreach($posts as $post)
    @boost([
        'key' => ['post-card', $post->show_author_badge], // changed
        'replace' => [
            '{name}' => $post->name,
            '{author}' => $post->author,
            '{url}' => route('post.show', $post),
        ]
    ])

            {title}

            @if($post->show_author_badge)
                {author}
            @endif

                Read More

    @endboost
@endforeach
```

### Large Component Use Case

[](#large-component-use-case)

Another common use case would be that you're rendering a page with a single components with many smaller other components.

```

                    Home

                    About

                    Contact

            &copy; {{ date('Y') }} {{ config('company.name') }}

```

To speed this up we can use the `@boost` directive to cache the HTML for the footer and only render it once. By default, `@boost` uses the `array` cache store, which is the fastest cache store available but is not persistent, this use case you'll want to use the `file` cache store. You can do this by passing a third argument to the `@boost` directive.

Let's see how we can use the `@boost` directive to speed this up.

```
@boost([
    'key' => 'footer',
    'store' => 'file'
    'replace' => [
        '{year}' => date('Y')
    ],
])

                        Home

                        About

                        Contact

                &copy; {year} {{ config('company.name') }}

@endboost
```

Now, Blade will just render this component once and store the HTML in the cache. The next time the page is loaded, the pre-rendered component will be stored in the `file` cache store. This is useful if you want to speed up large, but simple components that are used on every page and only rendered once.

### Simple Small Repeating Use Case

[](#simple-small-repeating-use-case)

Alternative syntax you can pass the key as the first parameter which is handle for simple cases where you don't need to pass any options, or you just prefer to pass the key as the first parameter.

```
@boost('recently-added-badge')

        Recently Added

@endboost
```

Mind you that the `@boost` directive will use the `Cache::rememberForever()` under the hood so it's up to you to clear the cache when you make changes to the component.

### Escaping

[](#escaping)

The `@boost` directive will escape the HTML by default using [Laravel's e() function](https://laravel.com/docs/strings#method-e). If you want to render the HTML without escaping, you can pass the `raw` option to the directive. This will allow you to output raw HTML without any escaping, which can be useful in certain scenarios where you trust the content being rendered.

```
@boost([
    'key' => 'raw-html',
    'replace' => [
        '{foo}' => 'bar'
    ],
    'raw' => true
])
```

### Cache Store

[](#cache-store)

The `@boost` directive will prefix the cache key with the `blade-boost-directive.` prefix which is configurable in the config file. This is to avoid collisions with other packages or parts of your application.

If you wish to clear a specific cache key, you can use the following.

```
// get the real cache key @boost uses
$key = \AngusMcRitchie\BladeBoostDirective\Boost::prefix('my-key');

cache()->store('array')->forget($key);
```

Configuration
-------------

[](#configuration)

You can publish the configuration file with the following command:

```
php artisan vendor:publish --tag="blade-boost-directive-config"
```

This is the contents of the published config file:

```
return [

    /**
     * Enable or disable the package.
     * If disabled, the package will not register any Blade directives.
     */
    'enabled' => env('BLADE_BOOST_ENABLED', true),

    /**
     * The default cache store to use.
     * This is used when no cache store is specified in the directive.
     */
    'default_cache_store' => env('BLADE_BOOST_DIRECTIVE_DEFAULT_CACHE_STORE', 'array'),

    /**
     * The prefix to use for cache keys.
     * This is used to avoid key collisions with other packages or parts of your application.
     */
    'prefix' => env('BLADE_BOOST_DIRECTIVE_PREFIX', 'blade-boost-directive.'),
];
```

Benchmarks
----------

[](#benchmarks)

Our [benchmarks](./benchmarks.md) show the performance improvements you can expect when using the `@boost` directive. The benchmarks are not exhaustive and only serve as a demonstration of the performance improvements you can expect.

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Angus McRitchie](https://github.com/angus-mcritchie)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

50

—

FairBetter than 96% of packages

Maintenance86

Actively maintained with recent releases

Popularity37

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 63.3% 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

Every ~27 days

Recently: every ~82 days

Total

13

Last Release

84d ago

Major Versions

v0.10 → v1.0.02025-04-02

### Community

Maintainers

![](https://www.gravatar.com/avatar/94145084d31157426f8e002c1949ba2fb62f774a39cfd3032753c9f818322c0e?d=identicon)[angus\_mcritchie](/maintainers/angus_mcritchie)

---

Top Contributors

[![angus-mcritchie](https://avatars.githubusercontent.com/u/53469513?v=4)](https://github.com/angus-mcritchie "angus-mcritchie (19 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (8 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (3 commits)")

---

Tags

bladeblade-directivesfluxlaravellivewireperformancerenderlaravelperformancebladecachespeedboostdirectiveoptimizeangus-mcritchieblade-boost-directive

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/angus-mcritchie-blade-boost-directive/health.svg)

```
[![Health](https://phpackages.com/badges/angus-mcritchie-blade-boost-directive/health.svg)](https://phpackages.com/packages/angus-mcritchie-blade-boost-directive)
```

###  Alternatives

[spatie/laravel-blade-javascript

A Blade directive to export variables to JavaScript

638855.8k9](/packages/spatie-laravel-blade-javascript)[spatie/laravel-blade-comments

Add debug comments to your rendered output

177325.5k](/packages/spatie-laravel-blade-comments)[daikazu/laravel-glider

Start using Glide on-the-fly instantly in your Laravel blade templates.

882.3k](/packages/daikazu-laravel-glider)

PHPackages © 2026

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