Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance Optimization: On-Demand CSS Loading for Language Switcher #110

Closed
wants to merge 2 commits into from

Conversation

n4ss1m
Copy link

@n4ss1m n4ss1m commented Dec 28, 2024

Changes Made

  • Implemented conditional loading of language switcher CSS using loadedOnRequest()
  • Added dynamic stylesheet loading via Alpine.js's x-load-css directive
  • Prevents loading of /css/bezhansalleh/filament-language-switch/filament-language-switch.css on pages where the language switcher isn't used

Technical Details

The core change utilizes Filament's loadedOnRequest() method, which ensures assets are only loaded when the component is actually rendered on the page. This replaces the previous behavior where the stylesheet was loaded globally across all pages.

Impact

  • Reduced unnecessary asset loading
  • Improved page load performance
  • Optimized bandwidth usage

Reference

https://filamentphp.com/docs/3.x/support/plugins/build-a-standalone-plugin#step-3-setting-up-the-provider
https://filamentphp.com/docs/3.x/support/plugins/build-a-standalone-plugin#step-5-rendering-our-component

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.
Copy link

what-the-diff bot commented Dec 28, 2024

PR Summary

  • Updated UI component for enhanced efficiency
    The 'language-switch.blade.php' file, which is a key part of our interface, has been updated. It now includes some additional instructions for loading stylesheets, known as Alpine.js directives. This will make the content appear more immersive and visually appealing to users.

  • Improved CSS loading for performance boost
    Our method to register (or load) style formats, technically known as CSS, in the 'FilamentLanguageSwitchServiceProvider.php' file, has been improved. Instead of loading them directly (which used to be heavy on resources), we've adopted a new 'lazy loading' approach. This will allow the styles to load only when requested, leading to faster page loading and better overall performance.

@n4ss1m n4ss1m closed this Dec 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant