Skip to content

perf: optimize Cloudflare Turnstile CAPTCHA loading on login#477

Merged
djavolak merged 1 commit intomainfrom
fix/optimize-turnstile-captcha-loading
Feb 10, 2026
Merged

perf: optimize Cloudflare Turnstile CAPTCHA loading on login#477
djavolak merged 1 commit intomainfrom
fix/optimize-turnstile-captcha-loading

Conversation

@vlazic
Copy link
Collaborator

@vlazic vlazic commented Feb 10, 2026

  • Add <link rel="preconnect"> for challenges.cloudflare.com in base.html.twig to save ~200-500ms on DNS/TCP/TLS
  • Switch Turnstile to interaction-only mode — widget is invisible unless Cloudflare needs human interaction, eliminating the visible "waiting for CAPTCHA" delay
  • Handle early form submissions: if user submits before the background challenge completes, the button shows "Molimo sačekajte..." and auto-submits when the token arrives

Test plan

  • Open /logovanje (not logged in), confirm no visible CAPTCHA widget appears
  • Type email and submit — form should submit immediately (challenge finishes while typing)
  • Test early submit (load page, immediately click submit) — button shows "Molimo sačekajte..." briefly, then auto-submits
  • Check DevTools Network tab — preconnect to challenges.cloudflare.com is present
  • Also test on /registracija-donatora and /postani-delegat
  • Verify logged-in users see no Turnstile markup")

Add preconnect hint for challenges.cloudflare.com to start DNS/TCP/TLS
early, and switch Turnstile to interaction-only mode so the widget is
invisible unless Cloudflare needs human interaction. Handle early form
submissions by deferring until the token is ready.
Copilot AI review requested due to automatic review settings February 10, 2026 10:32
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Optimizes Cloudflare Turnstile integration in Twig templates by reducing perceived latency and minimizing widget UI on user-facing forms.

Changes:

  • Updates the Turnstile widget to interaction-only mode and adds client-side submit deferral until a token is available.
  • Adds a preconnect hint for challenges.cloudflare.com to warm up DNS/TCP/TLS earlier.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
templates/captcha.html.twig Switches Turnstile configuration and adds JS to delay form submission until CAPTCHA completes.
templates/base.html.twig Adds a global preconnect hint for Cloudflare Turnstile’s domain.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@djavolak djavolak merged commit 1fc7a8d into main Feb 10, 2026
7 checks passed
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.

2 participants

Comments