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

[1.x] Manually inline Livewire assets #266

Merged
merged 7 commits into from
Jan 6, 2024
Merged

[1.x] Manually inline Livewire assets #266

merged 7 commits into from
Jan 6, 2024

Conversation

timacdonald
Copy link
Member

@timacdonald timacdonald commented Jan 5, 2024

We've had numerous reports of issues loading Livewire's dynamic /livewire/livewire.js route on deployed environments.

fixes #85, #131, #145, #164, #201, #263

This is a known issue that Livewire documents.

Screenshot 2024-01-05 at 2 54 10 pm

We have been telling people to update their NGINX configuration, however it would be nice if Pulse "just worked".

Livewire's recommend solution is to build their scripts into your app.js via a build tool, such as Vite. We cannot do this as we might build against Livewire 3.0.1 while the end user may install Livewire 3.3.0 that requires different built assets.

Instead we can inline Livewire's assets via file_get_contents. We will always output the correct Livewire assets for the currently installed Livewire version.

Having the assets cached at a URL is not really any benefit to Pulse. It makes sense for a full-blown Livewire application, but for a single page dashboard like Pulse it is fine to inline the assets and download them on every dashboard visit as you would usually be viewing the same page for some time and only occasionally doing full page reloads. We also do not need to consider SEO performance.

@timacdonald timacdonald changed the title [1.x] Assets [1.x] Manually inline Livewire assets Jan 5, 2024
@@ -50,7 +47,7 @@
</main>
</div>

@livewireScripts
@stack('scripts')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @stack('scripts') was a remnant from our previous iterations. We no longer use this.

@livewireStyles

{!! Laravel\Pulse\Facades\Pulse::js() !!}
@livewireScriptConfig
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When Livewire detects the @livewireScriptConfig directive, it will refrain from injecting the Livewire and Alpine scripts. If you are using the @livewireScripts directive to manually load Livewire, be sure to remove it. Make sure to add the @livewireStyles directive if it is not already present.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I initially thought we should remove our lock file, but we need it for our build step that commits the built assets.

I've updated the dependencies while I was looking at all this.

@taylorotwell taylorotwell merged commit 792e600 into 1.x Jan 6, 2024
11 checks passed
@taylorotwell taylorotwell deleted the assets branch January 6, 2024 17:06
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.

livewire.js gives 404 in production
4 participants