livewire/blaze
Blaze speeds up Laravel Blade anonymous components by compiling templates into optimized PHP functions. Drop-in replacement with no code changes. Optional memoization and folding for extra gains. Enable via @blaze directive or optimize directories.
composer require livewire/blaze:^1.0
@blaze
<button>{{ $slot }}</button>
Clear compiled views:
php artisan view:clear
Replace a slow-rendering anonymous component (e.g., a modal or button) with @blaze and measure the difference. Example:
@blaze
<div class="modal">
{{ $slot }}
</div>
@blaze on high-impact components (e.g., repeated UI elements like buttons, cards, or modals).AppServiceProvider:
Blaze::optimize()->in(resource_path('views/components'));
@blaze(memo: true) or @blaze(fold: true) for specific components.@if/@unless inside Blaze components (supported, but avoid global state).:color="$dynamicValue") via placeholders.Memoization for Icons:
@blaze(memo: true)
<x-dynamic-component :component="'icon-' . $name" />
Cache repeated renders (e.g., icons, avatars).
Folding for Static Content:
@blaze(fold: true)
<div class="static-content">{{ $staticText }}</div>
Pre-render static HTML (use cautiously; see Gotchas).
Hybrid Approach:
Blaze::optimize()
->in(resource_path('views/components/icons'), memo: true)
->in(resource_path('views/components/cards'), fold: true);
Combine strategies per directory.
Global State:
auth()->user(), now()).fold: true for components with:
User::find()).Cache::get()).@auth, @csrf).memo: true instead.Dynamic Props in @props:
@props (e.g., :color="$dynamicColor").fold: true only for static props or refactor to avoid conflicts.Slots with Dynamic Content:
{{ $user->name }}) may render incorrectly if folded.memo: true or avoid folding for such slots.Class-Based Components:
<x-Button /> with a PHP class).View Composers/Creators:
$__env->shared('key').php artisan view:clear after changes.Blaze::debug(); // Logs compilation warnings/errors
Custom Compilers:
BlazeCompiler to support custom syntax or logic.@blaze(optimize: 'custom') directive.Memoization Keys:
Blaze::memoizeUsing(function ($component, $props) {
return md5($component . serialize($props));
});
Folding Exclusions:
compile: false to exclude directories:
Blaze::optimize()
->in(resource_path('views/components/legacy'), compile: false);
@if($dynamicVar)).blade:profile to identify slow components before optimizing:
php artisan blade:profile
How can I help you explore Laravel packages today?