Skip to content

Commit

Permalink
Enable lazy loading for language switch CSS
Browse files Browse the repository at this point in the history
The CSS for the language switch is now set to load on demand using `loadedOnRequest()`. Additionally, the view is updated to dynamically load the required stylesheet using Alpine.js's `x-load-css` directive. This improves performance by reducing unnecessary asset loading.
  • Loading branch information
n4ss1m committed Dec 28, 2024
1 parent 8f91b80 commit 917527f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion resources/views/language-switch.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
};
$maxHeight = $languageSwitch->getMaxHeight();
@endphp
<div>
<div
x-data
x-load-css="[@js(\Filament\Support\Facades\FilamentAsset::getStyleHref('filament-language-switch', package: 'bezhansalleh/filament-language-switch'))]"
>
@if ($isVisibleOutsidePanels)
<div @class([
'fls-display-on fixed w-fit flex p-4 z-50',
Expand Down
2 changes: 1 addition & 1 deletion src/FilamentLanguageSwitchServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function packageBooted(): void

FilamentAsset::register(
assets: [
Css::make('filament-language-switch', __DIR__ . '/../resources/dist/filament-language-switch.css'),
Css::make('filament-language-switch', __DIR__ . '/../resources/dist/filament-language-switch.css')->loadedOnRequest(),
],
package: 'bezhansalleh/filament-language-switch'
);
Expand Down

0 comments on commit 917527f

Please sign in to comment.