ideal-creative-lab/laravel-tachyon
Installation:
composer require ideal-creative-lab/laravel-tachyon
Publish the config file:
php artisan vendor:publish --provider="IdealCreativeLab\Tachyon\TachyonServiceProvider" --tag="tachyon-config"
First Use Case:
Enable Tachyon for a specific route or globally in config/tachyon.php:
'enabled' => env('TACHYON_ENABLED', true),
Add middleware to app/Http/Kernel.php:
protected $middlewareGroups = [
'web' => [
// ...
\IdealCreativeLab\Tachyon\Middleware\OptimizeHtml::class,
],
];
Verify:
Visit a page and inspect the response headers for X-Tachyon-Optimized: true.
Selective Optimization: Use route-based middleware groups or middleware aliases to apply Tachyon only to specific routes:
Route::middleware(['tachyon'])->group(function () {
Route::get('/optimized-page', [PageController::class, 'show']);
});
Livewire Integration:
Exclude Livewire components from optimization by wrapping them in a tachyon:ignore directive:
@tachyon:ignore
<livewire:component />
@endtachyon
Or via Blade:
<div data-tachyon-ignore>
<livewire:component />
</div>
Dynamic Exclusions: Exclude dynamic content (e.g., user-specific data) via config:
'excluded_selectors' => [
'.user-specific-data',
'[data-dynamic]',
],
Conditional Optimization: Disable Tachyon for specific IPs or user agents:
'skip_for' => [
'ips' => ['127.0.0.1'],
'user_agents' => ['MobileApp/1.0'],
],
@tachyon:ignore to exclude blocks from optimization.$this->app->bind(
\IdealCreativeLab\Tachyon\Contracts\HtmlProcessor::class,
\App\Services\CustomHtmlProcessor::class
);
Tachyon::shouldOptimize(false).Caching Headaches:
Cache::forget('html_*') or adjust cache keys to avoid stale content.Livewire Conflicts:
'livewire_exclusions' => [
'components' => ['livewire:admin-dashboard'],
'attributes' => ['wire:init', 'wire:model'],
],
CSS/JS Inlining:
config/tachyon.php:
'inline_critical' => false,
Debugging:
php artisan tachyon:disable
tail -f storage/logs/laravel.log | grep Tachyon
Performance Tuning:
tachyon:analyze to profile optimization impact:
php artisan tachyon:analyze /path-to-view
optimization_level (0–10) in config for granular control.Exclusion Strategies:
Tachyon::excludeIf(fn () => Auth::user()->isAdmin());
Custom Processors:
namespace App\Services;
use IdealCreativeLab\Tachyon\Contracts\HtmlProcessor;
class CustomProcessor implements HtmlProcessor {
public function process(string $html): string {
// Custom logic (e.g., lazy-load images)
return $html;
}
}
Environment Awareness:
config/tachyon.php for local/staging:
'enabled' => app()->environment(['production']),
Blade Debugging:
@tachyon:debug to inspect optimized HTML:
@tachyon:debug
<div>Content to debug</div>
@endtachyon
How can I help you explore Laravel packages today?