PHPackages                             swiss-devjoy/blade-staticcache-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. swiss-devjoy/blade-staticcache-directive

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

swiss-devjoy/blade-staticcache-directive
========================================

Put chunks of your Blade template into immutable static cache files

v1.1.0(11mo ago)12.0kMITPHPPHP ^8.2CI passing

Since Apr 16Pushed 11mo ago1 watchersCompare

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

READMEChangelog (2)Dependencies (9)Versions (3)Used By (0)

Put chunks of your Blade template into immutable static cache files
===================================================================

[](#put-chunks-of-your-blade-template-into-immutable-static-cache-files)

[![Latest Version on Packagist](https://camo.githubusercontent.com/0c073654949cbf245d3c58b651d1c9febf943b4a671e9b6ed7764cac0eefded2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73776973732d6465766a6f792f626c6164652d73746174696363616368652d6469726563746976652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/swiss-devjoy/blade-staticcache-directive)[![Total Downloads](https://camo.githubusercontent.com/7ecda1db7cb481779e703866df680e8cc85ebd54ef202fd953b9cbc10393c097/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73776973732d6465766a6f792f626c6164652d73746174696363616368652d6469726563746976652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/swiss-devjoy/blade-staticcache-directive)

Increase performance by putting chunks of your Blade template into immutable static cache files. This package provides a directive for Blade templates that allows you to easily create static cache files for specific sections of your views. With OPCache enabled, this can significantly reduce the time it takes to render your views, especially for large and complex templates.

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

[](#installation)

You can install the package via composer:

```
composer require swiss-devjoy/blade-staticcache-directive
```

You can publish the config file with:

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

This is the contents of the published config file:

```
return [
    'enabled' => env('BLADE_STATICCACHE_DIRECTIVE_ENABLED', true),
    'strip_whitespace_between_tags' => env('BLADE_STATICCACHE_DIRECTIVE_STRIP_WHITESPACE_BETWEEN_TAGS', true),

    // Cache profile which generates the unique key for the cache entry
    'cache_profile' => \SwissDevjoy\BladeStaticcacheDirective\CacheProfile::class,
];
```

Usage
-----

[](#usage)

```
This is a blade template.

@staticcache('my-cache-key')
    {{ $this->aVeryExpensiveMethod() }}
@endstaticcache
```

To clear the cache you can run the following command:

```
$ php artisan blade-staticcache:clear
```

To include some additional stats in your response about cached/uncached blade chunks, you can use the provided middleware:

**For laravel 11.x and newer:**

Add the middleware definition to the bootstrap app.

```
// bootstrap/app.php

->withMiddleware(function (Middleware $middleware) {
    ...
    $middleware->web(append: [
        ...
        \SwissDevjoy\BladeStaticcacheDirective\BladeStaticcacheStatsMiddleware::class,
    ]);
})
```

**For laravel 10.x and earlier:**

Add the middleware definition to the http kernel.

```
// app/Http/Kernel.php

...

protected $middlewareGroups = [
   'web' => [
       ...
       \SwissDevjoy\BladeStaticcacheDirective\BladeStaticcacheStatsMiddleware::class,
   ],
```

Cache Profile
-------------

[](#cache-profile)

The cache profile is responsible for generating the unique key for the cache entry. By default, it uses the `\SwissDevjoy\BladeStaticcacheDirective\CacheProfile` class, which generates a key based on the cache key parameter passed to the `@staticcache` directive AND the current locale.

Inspiration
-----------

[](#inspiration)

The main idea came from a tweet () and the following package:

I did some basic benchmarks with a huge template and a lot of data.

Using Ryan's package and `redis` as a cache driver, I got 85 req/s. Using Ryan's package and `file` as a cache driver, I got 99 req/s. Using my package, I got 110 req/s.

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)

- [Dimitri König](https://github.com/dimitri-koenig)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance51

Moderate activity, may be stable

Popularity17

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

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

Every ~51 days

Total

2

Last Release

346d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/94ba6c20d1e53a2066e9df02d8fe50390629cc344e16531f552c843c32032180?d=identicon)[dimitri-koenig](/maintainers/dimitri-koenig)

---

Top Contributors

[![dimitri-koenig](https://avatars.githubusercontent.com/u/4375825?v=4)](https://github.com/dimitri-koenig "dimitri-koenig (6 commits)")

---

Tags

bladelaravelperformancephplaraveldevjoy.chblade-staticcache-directive

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/swiss-devjoy-blade-staticcache-directive/health.svg)

```
[![Health](https://phpackages.com/badges/swiss-devjoy-blade-staticcache-directive/health.svg)](https://phpackages.com/packages/swiss-devjoy-blade-staticcache-directive)
```

###  Alternatives

[ryangjchandler/blade-capture-directive

Create inline partials in your Blade templates with ease.

8222.2M12](/packages/ryangjchandler-blade-capture-directive)[spatie/laravel-blade-comments

Add debug comments to your rendered output

177325.5k](/packages/spatie-laravel-blade-comments)[vormkracht10/laravel-mails

Laravel Mails can collect everything you might want to track about the mails that has been sent by your Laravel app.

24149.7k](/packages/vormkracht10-laravel-mails)[daikazu/laravel-glider

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

882.3k](/packages/daikazu-laravel-glider)[combindma/dash-ui

A streamlined and stylish UI component library for Laravel Blade, crafted with TailwindCSS and AlpineJs for simplicity and elegance.

631.4k](/packages/combindma-dash-ui)

PHPackages © 2026

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