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

Lazy load assets #38

Merged
merged 2 commits into from
Sep 17, 2024
Merged

Conversation

tanthammar
Copy link
Contributor

@tanthammar tanthammar commented Sep 13, 2024

This PR can only be accepted when Filament uses the latest version of Alpine lazy load assets.
filamentphp/filament#14239

Description

Filament includes an Alpine plugin to lazy load assets, this PR adds support for that.
Meaning that the js and css needed for this filament field, will only be loaded on pages where it is actually being used.
https://www.npmjs.com/package/alpine-lazy-load-assets

I have tested the changes with Filament spa mode enabled/disabled

Changes to the service provider

  • it uses this package name, not other plugin author, to avoid potential naming conflicts
  • it tells Filament to load the assets when requested, not on every page.

Changes to the blade file

  • it loads the assets only on pages where the field is used
  • it pushes css to the head
  • it makes sure the script is loaded before app.js
  • it dispatches a window event when the script is loaded
  • it delays initiation of the field until the script is loaded
  • it properly destroys the input when on Alpine.destroy()
  • it prevents re-initiating the field if the window event is dispatched multiple times
  • it checks that JSONEditor is available

@invaders-xx invaders-xx merged commit 4e5deda into invaders-xx:main Sep 17, 2024
2 of 9 checks passed
@tanthammar tanthammar deleted the lazy-load-assets branch September 18, 2024 09:56
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.

2 participants