Defer the Turnstile api.js head script (parser-blocking on every page)#6
Open
ekumanov wants to merge 1 commit into
Open
Defer the Turnstile api.js head script (parser-blocking on every page)#6ekumanov wants to merge 1 commit into
ekumanov wants to merge 1 commit into
Conversation
A classic <script> in <head> parser-blocks every page render behind a third-party fetch (DNS + TLS + ~30 KB from challenges.cloudflare.com), roughly 150-400 ms at mobile p75, on all pages including ones that never show an auth modal. With defer the script downloads in parallel and runs right after DOM parsing - still well before a user can open an auth modal, so window.turnstile is ready when TurnstileState.render() runs. Fixes flectar#5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
One-line fix for #5: add
deferto the injectedapi.jsscript tag so it no longer parser-blocks every page render behind a third-party fetch (~150–400 ms at mobile p75; flagged by PSI's render-blocking audit and it delays FCP/LCP directly).deferdownloads in parallel and executes right after DOM parsing — still well before a user can open an auth modal, sowindow.turnstileis available whenTurnstileState.render()runs.render=explicitsemantics are unchanged.Running in production on a Flarum 2.0.0-rc.4 forum: pages no longer block on
challenges.cloudflare.com, and the sign-up widget renders and completes normally.If you'd also like the
?onload=+ pending-render-queue hardening described in #5 (covers the theoretical modal-open-before-DOM-parsed race), happy to follow up with that separately.