PHPackages                             mvaliolahi/blaze - 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. mvaliolahi/blaze

ActiveLibrary

mvaliolahi/blaze
================

A Laravel package for speedup laravel routes by generate an static version of them.

v1.0.1(1y ago)3716PHPPHP ^7.3|^8.0

Since Jul 19Pushed 1y ago3 watchersCompare

[ Source](https://github.com/mvaliolahi/blaze)[ Packagist](https://packagist.org/packages/mvaliolahi/blaze)[ RSS](/packages/mvaliolahi-blaze/feed)WikiDiscussions master Synced 1mo ago

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

Blaze - Accelerate Laravel with Rocket-Like Speed
=================================================

[](#blaze---accelerate-laravel-with-rocket-like-speed)

Introduction
------------

[](#introduction)

Blaze is a versatile package that revolutionizes the way you build websites in Laravel. By seamlessly combining dynamic and static content generation, Blaze empowers developers to create high-performance websites with ease. With Blaze, you can achieve an average response time of just 4 milliseconds, ensuring lightning-fast performance for your applications. This comprehensive README.md will guide you through the setup and usage of Blaze, enabling you to harness its full potential for building dynamic and static websites in Laravel.

Here's a more detailed diagram illustrating how Blaze interacts with Laravel and Nginx for dynamic and static content generation, along with cache invalidation:

```
              +-----------------+       +-----------------+       +-----------------+
              |    Laravel      |       |     Nginx       |       |     Blaze       |
              |   Application   |       |   Web Server    |       |   Integration   |
              +-----------------+       +-----------------+       +-----------------+
                      |                        |                      |
                      | HTTP Requests/Responses|                      |
                      | ---------------------->|                      |
                      |                        |                      |
                      |   Dynamic Routes       |                      |
                      | ---------------------> |                      |
                      |                        |                      |
                      |                        |                      |
                      |  Static Files Serving  |                      |
                      |  (Cache Hit)           |                      |
                      |  |                      |
                      |                        |                      |
                      |   Cache File Creation  |                      |
                      |                        |                      |
                      | |
                      |                        |                      |
                      |                        |                      |
                      | Cache File Serving     |                      |
                      | (Cache Hit)            |                      |
                      |  |                      |
                      |                        |                      |
                      |                        | Cache File Removal   |
                      |                        | -------------------->|
                      |                        |                      |
                      |                        |                      |
                      |                        |                      |
                      |                        |                      |
              +-----------------+       +-----------------+       +-----------------+
              |   PHP-FPM       |       |   File System   |       |   Cache Files   |
              |   Process       |       |   (Serving      |       |                 |
              |   Manager       |       |   Static Files) |       |                 |
              +-----------------+       +-----------------+       +-----------------+

```

1. HTTP requests are initially received by Nginx.
2. Nginx forwards dynamic requests to the Laravel application.
3. Laravel processes dynamic routes and generates responses for dynamic content.
4. Responses are served to clients directly or cached by Blaze as static files.
5. For cache hits, Nginx serves static files directly, bypassing Laravel for improved performance.
6. If a cache miss occurs, Blaze generates cache files for the dynamic content and stores them.
7. Cached files are served by Nginx for subsequent requests until invalidated.
8. Cache invalidation can occur due to model changes, custom events, or other triggers.
9. Upon invalidation, Blaze removes outdated cache files to ensure fresh content delivery.
10. The cycle continues, providing a seamless blend of dynamic and static content delivery for optimal performance.

Note: having nginx is not required but using the provided config can significantly improve response time.

Features
--------

[](#features)

- **Dynamic-Static Fusion:** Blaze seamlessly integrates dynamic and static content generation, offering the best of both worlds for website performance and scalability.
- **Automatic Content Rendering:** Blaze automates content rendering and caching, ensuring lightning-fast response times and optimal user experience.
- **Flexible Configuration:** Customize Blaze to fit your project's requirements with its flexible configuration options and intuitive design.

Getting Started
---------------

[](#getting-started)

### 1. Installation

[](#1-installation)

- Install Blaze via Composer: ```
    composer require mvaliolahi/blaze
    ```

### 2. Configuration

[](#2-configuration)

- Add `blaze_id` to your `EncryptCookies` middleware like this:

```
class EncryptCookies extends Middleware
{
    protected $except = [
        'blaze_id',
    ];
}
```

You should also add `@blaze` directive before the body tag ends for handle csrf.

### 3. Adding Blaze to Routes

[](#3-adding-blaze-to-routes)

- Blaze introduces two types of caching: `private` and `public`.

    - **Private Routes:** These routes are personalized and may display user-specific content. Use the `blaze:private` middleware to mark routes as private.
    - **Public Routes:** These routes are static and serve the same content to all users. Use the `blaze:public` middleware to mark routes as public.
- Example:

    ```
    Route::get('/profile', [ProfileController::class, 'show'])->middleware('blaze:private');
    Route::get('/posts', [PostController::class, 'index'])->middleware('blaze:public');
    ```

    ### Difference between `blaze:private` and `blaze:public`

    [](#difference-between-blazeprivate-and-blazepublic)

    - **Private Routes (`blaze:private`):** These routes are personalized and may display user-specific content. Blaze stores separate cache files for each user, identified by a unique `blaze_id` cookie. Changes to user-specific data invalidate the cache for that user only.
    - **Public Routes (`blaze:public`):** These routes serve static content to all users. Blaze generates a single cache file for each public route, optimizing performance by serving pre-rendered HTML files.

### 4. Config the model for invalidating and refreshing the cache

[](#4-config-the-model-for-invalidating-and-refreshing-the-cache)

- **Model Integration:**

    - Add the `Blaze` trait to your models to enable dynamic content generation.
    - Define which routes should be invalid and whether they are public or private in the `$blaze` property of your models.
- **Cache Invalidation:**

    - Blaze observes model changes and invalidates cache files associated with affected routes, ensuring content remains up-to-date.

    ### Examples

    [](#examples)

    - Below is an example of how you can integrate Blaze into your Laravel models for dynamic-static fusion: ```
        class Page extends Model
        {
            use Blaze;

            protected $blaze_refresh = true;

            protected $blaze = [
                'private' => ['profile', 'settings'],
                'public'  => ['homepage', 'posts.index'],
            ];
        }
        ```

    Define `blaze_refresh = true`, which will automatically update the cache by calling related routes regarding the $blaze array, note that enabling this feature may affect response time.

### 5. Nginx Config

[](#5-nginx-config)

- Add below map inside http {}

```
  # Map to replace forward slashes with underscores
  map $uri $sanitized_uri {
    ~/(.*) _$1;
    default $uri;
  }

  # Define a variable based on the presence of the blaze_id cookie
  map $http_cookie $blaze_id {
    default "";
    "~*blaze_id=([^;]+)(?:;|$)" $1;
  }
```

After that change / location to:

```
location / {
    etag off;

    # 1. All method except GET must be proxied to PHP-FPM (post, put, patch, delete)
    if ($request_method !~ ^(GET)$ ) {
        rewrite ^ /index.php$query_string last;
    }

    # 2. detect blaze identifier using map
    # 3. Sanitize the URI for match cache file using map.
    rewrite ^/(.*)[/?&=](.*)$ /$1_$2;

    # 4. Set the paths for private and public cache files
    set $private_cache_file "/cache/${blaze_id}_${sanitized_uri}?${query_string}.html";
    set $public_cache_file "/cache/public_${sanitized_uri}?${query_string}.html";

    # 5. Try to serve the private cached file if it exists, then the public cached file, and finally index.php
    try_files $private_cache_file $public_cache_file /index.php?$query_string;
}
```

### TODO

[](#todo)

- \[\] Artisan command for cache public and private routes for add users.
- \[\] Minify static file.

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity46

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 ~36 days

Total

2

Last Release

630d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6d8a3eaee2623560bfdc9906358e1805abd4adf9fcd9170eba274fcfd8a51443?d=identicon)[mvaliolahi](/maintainers/mvaliolahi)

---

Top Contributors

[![mvaliolahi](https://avatars.githubusercontent.com/u/6920600?v=4)](https://github.com/mvaliolahi "mvaliolahi (2 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mvaliolahi-blaze/health.svg)

```
[![Health](https://phpackages.com/badges/mvaliolahi-blaze/health.svg)](https://phpackages.com/packages/mvaliolahi-blaze)
```

###  Alternatives

[s-ichikawa/laravel-sendgrid-driver

This library adds a 'sendgrid' mail driver to Laravel.

4139.3M1](/packages/s-ichikawa-laravel-sendgrid-driver)[stechstudio/laravel-zipstream

A fast and simple streaming zip file downloader for Laravel.

4633.7M3](/packages/stechstudio-laravel-zipstream)[laravel-notification-channels/microsoft-teams

A Laravel Notification Channel for Microsoft Teams

1603.0M7](/packages/laravel-notification-channels-microsoft-teams)[spatie/laravel-export

Create a static site bundle from a Laravel app

646127.9k5](/packages/spatie-laravel-export)[erag/laravel-disposable-email

A Laravel package to detect and block disposable email addresses.

226102.4k](/packages/erag-laravel-disposable-email)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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