Skip to content

Commit a21ed1d

Browse files
committed
make turnstile script async
1 parent 24d6b39 commit a21ed1d

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

resources/views/components/turnstile/scripts.blade.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11

22
@php($nonce = \Illuminate\Support\Facades\Vite::cspNonce())
33

4+
<link rel="preconnect" href="https://challenges.cloudflare.com" />
45
<script
56
id="turnstile-script"
67
src="https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit"
78
defer
9+
async
810
{{ $attributes->merge(['nonce' => $nonce]) }}
911
></script>
1012

resources/views/components/turnstile/widget.blade.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
reset() {
2323
turnstile.reset(this.widgetId);
2424
},
25-
init() {
25+
initCaptcha() {
2626
if($el.hasAttribute('data-invisible')) {
2727
this.load();
2828
} else {
@@ -56,6 +56,13 @@
5656
this.reset();
5757
}
5858
});
59+
},
60+
init() {
61+
if('turnstile' in window) {
62+
this.initCaptcha();
63+
} else {
64+
document.querySelector('#turnstile-script').addEventListener('load', () => this.initCaptcha());
65+
}
5966
}
6067
}"
6168
data-captcha

0 commit comments

Comments
 (0)