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.
Livewire/Blaze is a drop-in optimization for Laravel Blade components, specifically targeting anonymous components (not class-based). It replaces the standard Blade rendering pipeline with pre-compiled PHP functions, eliminating 91-97% of rendering overhead while maintaining near-full feature parity. This aligns well with modern Laravel applications where:
Key Fit Criteria:
✅ Anonymous Blade components (primary target).
✅ No changes to existing code (drop-in via @blaze directive or directory optimization).
✅ Compatibility with Livewire/Alpine (Flux UI integration).
❌ Not suitable for class-based components (e.g., php artisan make:component).
❌ Limited support for Blade features (e.g., @stack, @section, @inject, @can).
Blaze integrates via two mechanisms:
@blaze directive in Blade files).Blaze::optimize() in AppServiceProvider).Feasibility Assessment:
| Integration Path | Effort | Risk | Best For |
|---|---|---|---|
| Opt-in per component | Low | Minimal (test edge cases) | Gradual adoption, A/B testing |
| Directory optimization | Medium | Higher (feature parity testing) | Large-scale rollouts, performance-critical apps |
| Folding/Memoization | High | High (global state, dynamic logic) | Static-heavy components (icons, cards) |
Compatibility:
view:clear after enabling (cache invalidation).Key Risks:
@auth, now()) may break folded components.@aware or unsupported Blade features may fail silently.| Risk Area | Severity | Mitigation |
|---|---|---|
| Folding breaking dynamic logic | High | Start with @blaze (no folding), test thoroughly before enabling fold: true. |
| Memoization stale data | Medium | Avoid for components with side effects (e.g., tracking clicks). |
| Blade feature gaps | Medium | Audit components for unsupported features (e.g., @stack, @inject). |
| Cache invalidation | Low | Run php artisan view:clear post-deployment. |
| Livewire/Alpine conflicts | Low | Test with Flux UI or Alpine.js integrations. |
Critical Questions for TPM:
view:clear? (Automate cache invalidation.)Blaze is optimized for Laravel ecosystems where:
Best Stack Matches: ✅ Laravel + Livewire/Alpine (Flux UI, Tailwind, Inertia.js). ✅ Component-heavy UIs (admin panels, dashboards). ✅ Static-heavy apps (marketing sites, documentation).
Poor Fit:
❌ Class-based components (e.g., php artisan make:component).
❌ Heavy server-side logic (Blaze optimizes rendering, not business logic).
❌ Dynamic content with global state (e.g., @auth, now()).
| Phase | Action | Tools/Validation |
|---|---|---|
| 1. Assessment | Profile Blade rendering bottlenecks (e.g., Xdebug, Laravel Debugbar). | telescope:record for slow component renders. |
| 2. Pilot Testing | Add @blaze to 1-2 high-impact components. |
A/B test performance (e.g., GTmetrix). |
| 3. Directory Opt-in | Enable Blaze::optimize() for non-critical directories. |
Feature flags for gradual rollout. |
| 4. Advanced Strategies | Enable memo: true or fold: true for static components. |
Unit tests for folded components. |
| 5. Full Rollout | Optimize remaining directories, monitor errors. | Sentry/New Relic for runtime issues. |
Sequencing Recommendations:
@blaze directives (low risk, easy rollback).memo: true first)./views/auth, /views/reports).| Feature | Supported? | Notes |
|---|---|---|
| Anonymous Blade components | ✅ Yes | Primary target. |
| Class-based components | ❌ No | Use standard Blade rendering. |
@props |
✅ Yes | Works with function compilation. |
| Slots | ✅ Yes | Placeholder-based (no folding for unsafe slots). |
@aware |
⚠️ Partial | Both parent/child must use Blaze. |
@stack/@section |
❌ No | Not supported. |
@inject |
❌ No | Use $__env->shared() as workaround. |
| Livewire/Alpine | ✅ Yes | Flux UI integration out-of-the-box. |
| Memoization | ✅ Yes | Only for components without slots. |
| Folding | ✅ Yes | High caution: Global state breaks folding. |
Workarounds for Unsupported Features:
@inject with $__env->shared('key').{{ $__env->yieldContent('section') }} for @section compatibility.@auth, @guest, or now() in folded components.| Aspect | Impact | Mitigation |
|---|---|---|
| Compiled views | Blaze increases compiled view size (folding embeds HTML). | Monitor disk space; optimize with view:clear. |
| Cache invalidation | view:clear required after Blaze changes. |
Automate in CI/CD (e.g., post-deploy script). |
| Debugging | Folded components are static; runtime errors harder to trace. | Log warnings for unsupported features. |
| Dependency updates | Blaze is tied to Laravel/Livewire versions. | Pin versions in composer.json. |
Maintenance Tasks:
@blaze and their strategies.| Issue Type | Likelihood | Resolution Path |
|---|---|---|
| Folding breaking | High | Revert to @blaze (no folding), refactor logic. |
| Memoization stale data | Medium | Disable memoization; use @blaze only. |
| Blade feature gaps | Medium | Workarounds (e.g., $__env->shared()). |
| Livewire conflicts | Low | Test with Flux |
How can I help you explore Laravel packages today?