-
-
Notifications
You must be signed in to change notification settings - Fork 549
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
[5.x] Move nocache js back to end of body but make configurable #10898
Conversation
Brill, thanks for sorting so quickly. Just so I understand though, if you want it in the head (for livewire) this means any other nocache tags on the page wont work, ie you can't mix them. Surely the best solution for livewire would be to have it defined as a function (window.StatamicNoCacheReplace) so you could call it when you want? |
Why would you want the nocache stuff in the head when you use livewire? |
On pages you don't use livewire, like a form. |
Correct. I guess you go all in on Livewire.
Probably, yes. A JS solution was offered in that PR where you can defer it to after nocache. I suppose they could do that too. |
Appreciate the directions guys, but you’ve all lost me. I guess I’ll just bug you all when stuff breaks. So, nothing new basically 😂. |
What's the issue? Something broke and we reverted it. It should be like nothing changed on your end. |
Oh don’t worry, no issue at all. I’m just trying to keep up with changes. 😘 And now I’ll sort myself out. |
Thinking about this some more. As @ryanmitchell pointed out, you won't be able to have both Livewire and Having the nocache replacer script in the A simple solution is to bundle Livewire yourself and only start it once the token has been replaced. However, the problem with this is that the start of Alpine is delayed as well, leading to unnecessary delay. if (window.livewireScriptConfig?.csrf === 'STATAMIC_CSRF_TOKEN') {
document.addEventListener('statamic:nocache.replaced', () => Livewire.start());
} else {
Livewire.start();
} The best solution for this issue might be to have a separate route and script for getting the CSRF token to ensure a quick initialization. This CSRF script could be in the What do you think @jasonvarga? |
* Nocache database driver Related: statamic/cms#10671 * Prevent query parameters bloating the static cache Related: statamic/cms#10701 * Add entry password protection Related: statamic/cms#10800 * Fix small typo Related: statamic/cms#10824 * Move nocache js back to end of body but make configurable Related: statamic/cms#10898
The position option was only introduced in statamic#10898 to allow either Livewire or nocache to work. We can revert all this code as we’ve now got a separate CSRF route that will solve the Livewire issue.
The Nocache JS was originally inserted at the end of the body, so any replacements happen after all the HTML is ready.
In #10306 the JS was moved into the head so it's ready before any Livewire. This broke non-Livewire usage.
This PR reverts it to the body by default, but adds a config option so that you can move it into the head if you need it for your situation.
Fixes #10890