Skip to content

Commit a49cf62

Browse files
authored
Merge pull request #21 from tanthammar/patch-1
lazy load assets and avoid push scripts
2 parents 66584d3 + 592a91e commit a49cf62

File tree

1 file changed

+12
-21
lines changed

1 file changed

+12
-21
lines changed

resources/views/components/turnstile.blade.php

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
<x-dynamic-component :component="$fieldWrapperView" :field="$turnstile">
1111

1212
<div x-data="{
13-
state: $wire.entangle('{{ $statePath }}').defer
13+
state: $wire.entangle('{{ $statePath }}').defer
1414
}"
15-
wire:ignore
16-
x-init="(() => {
15+
wire:ignore
16+
x-load-js="['https://challenges.cloudflare.com/turnstile/v0/api.js?onload=onloadTurnstileCallback']"
17+
x-init="(() => {
1718
let options= {
1819
callback: function (token) {
1920
$wire.set('{{ $statePath }}', token)
@@ -31,26 +32,16 @@
3132
resetCaptcha = () => {
3233
turnstile.reset($refs.turnstile)
3334
}
35+
36+
$wire.on('reset-captcha', () => resetCaptcha())
3437
})()"
3538
>
3639
<div data-sitekey="{{config('turnstile.turnstile_site_key')}}"
37-
data-theme="{{ $theme }}"
38-
data-language="{{ $language }}"
39-
data-size="{{ $size }}"
40-
x-ref="turnstile"
41-
>
40+
data-theme="{{ $theme }}"
41+
data-language="{{ $language }}"
42+
data-size="{{ $size }}"
43+
x-ref="turnstile"
44+
>
4245
</div>
4346
</div>
44-
45-
<script src="https://challenges.cloudflare.com/turnstile/v0/api.js?onload=onloadTurnstileCallback" defer></script>
46-
47-
@push('scripts')
48-
<script>
49-
document.addEventListener('livewire:init', () => {
50-
Livewire.on('reset-captcha', (event) => {
51-
resetCaptcha()
52-
})
53-
})
54-
</script>
55-
@endpush
56-
</x-dynamic-component>
47+
</x-dynamic-component>

0 commit comments

Comments
 (0)