diff --git a/packages/panels/docs/01-installation.md b/packages/panels/docs/01-installation.md index 1cfc55062c..e3e4fbfe00 100644 --- a/packages/panels/docs/01-installation.md +++ b/packages/panels/docs/01-installation.md @@ -42,18 +42,34 @@ The Filament Panel Builder pre-installs the [Form Builder](/docs/forms), [Table ## Improving Filament panel performance -### Caching Blade Icons +### Optimizing Filament for production -You may wish to consider running `php artisan icons:cache` locally, and also in your deployment script. This is because Filament uses the [Blade Icons](https://blade-ui-kit.com/blade-icons) package, which can be much more performant when cached. +To optimize Filament for production, you should run the following command in your deployment script: -### Caching Filament components +```bash +php artisan filament:optimize +``` -You may also wish to consider running `php artisan filament:cache-components` in your deployment script, especially if you have large numbers of components (resources, pages, widgets, relation managers, custom Livewire components, etc.). This will create cache files in the `bootstrap/cache/filament` directory of your application, which contain indexes for each type of component. This can significantly improve the performance of Filament in some apps, as it reduces the number of files that need to be scanned and auto-discovered for components. +This command will [cache the Filament components](#caching-filament-components) and additionally the [Blade icons](#caching-blade-icons), which can significantly improve the performance of your Filament panels. This command is a shorthand for the commands `php artisan filament:cache-components` and `php artisan icons:cache`. + +To clear the caches at once, you can run: + +```bash +php artisan filament:optimize-clear +``` + +#### Caching Filament components + +If you're not using the [`filament:optimize` command](#optimizing-filament-for-production), you may wish to consider running `php artisan filament:cache-components` in your deployment script, especially if you have large numbers of components (resources, pages, widgets, relation managers, custom Livewire components, etc.). This will create cache files in the `bootstrap/cache/filament` directory of your application, which contain indexes for each type of component. This can significantly improve the performance of Filament in some apps, as it reduces the number of files that need to be scanned and auto-discovered for components. However, if you are actively developing your app locally, you should avoid using this command, as it will prevent any new components from being discovered until the cache is cleared or rebuilt. You can clear the cache at any time without rebuilding it by running `php artisan filament:clear-cached-components`. +#### Caching Blade Icons + +If you're not using the [`filament:optimize` command](#optimizing-filament-for-production), you may wish to consider running `php artisan icons:cache` locally, and also in your deployment script. This is because Filament uses the [Blade Icons](https://blade-ui-kit.com/blade-icons) package, which can be much more performant when cached. + ### Enabling OPcache on your server From the [Laravel Forge documentation](https://forge.laravel.com/docs/servers/php.html#opcache): diff --git a/packages/support/src/Commands/Concerns/CanCachePanelComponents.php b/packages/support/src/Commands/Concerns/CanCachePanelComponents.php new file mode 100644 index 0000000000..cfbeb0749d --- /dev/null +++ b/packages/support/src/Commands/Concerns/CanCachePanelComponents.php @@ -0,0 +1,13 @@ +components->info('Clearing cached components and Blade icons.'); + + $tasks = collect(); + + if ($this->canCachePanelComponents()) { + $tasks->put( + 'Clearing cached components', + fn (): bool => $this->callSilent('filament:clear-cached-components') === static::SUCCESS + ); + } + + $tasks->put( + 'Clearing cached Blade icons', + fn (): bool => $this->callSilent('icons:clear') === static::SUCCESS + ); + + $tasks->each(fn (Closure $task, string $description) => $this->components->task($description, $task)); + + $this->newLine(); + + return static::SUCCESS; + } +} diff --git a/packages/support/src/Commands/OptimizeCommand.php b/packages/support/src/Commands/OptimizeCommand.php new file mode 100644 index 0000000000..d26219f757 --- /dev/null +++ b/packages/support/src/Commands/OptimizeCommand.php @@ -0,0 +1,40 @@ +components->info('Caching components and Blade icons.'); + + $tasks = collect(); + + if ($this->canCachePanelComponents()) { + $tasks->put( + 'Caching components', + fn (): bool => $this->callSilent('filament:cache-components') === static::SUCCESS + ); + } + + $tasks->put('Caching Blade icons', fn (): bool => $this->callSilent('icons:cache') === static::SUCCESS); + + $tasks->each(fn (Closure $task, string $description) => $this->components->task($description, $task)); + + $this->newLine(); + + return static::SUCCESS; + } +} diff --git a/packages/support/src/SupportServiceProvider.php b/packages/support/src/SupportServiceProvider.php index 59e30cf275..0b1015a6df 100644 --- a/packages/support/src/SupportServiceProvider.php +++ b/packages/support/src/SupportServiceProvider.php @@ -12,6 +12,8 @@ use Filament\Support\Commands\AssetsCommand; use Filament\Support\Commands\CheckTranslationsCommand; use Filament\Support\Commands\InstallCommand; use Filament\Support\Commands\MakeIssueCommand; +use Filament\Support\Commands\OptimizeClearCommand; +use Filament\Support\Commands\OptimizeCommand; use Filament\Support\Commands\UpgradeCommand; use Filament\Support\Components\ComponentManager; use Filament\Support\Components\Contracts\ScopedComponentManager; @@ -40,10 +42,11 @@ class SupportServiceProvider extends PackageServiceProvider AssetsCommand::class, CheckTranslationsCommand::class, InstallCommand::class, - UpgradeCommand::class, - MakeIssueCommand::class, MakeIssueCommandAlias::class, + OptimizeClearCommand::class, + OptimizeCommand::class, + UpgradeCommand::class, ]) ->hasConfigFile() ->hasTranslations()