Skip to content
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

LG-15612 Load reCAPTCHA script earlier in the page #11880

Merged
merged 9 commits into from
Feb 18, 2025

Conversation

kevinsmaster5
Copy link
Contributor

@kevinsmaster5 kevinsmaster5 commented Feb 14, 2025

🎫 Ticket

Link to the relevant ticket:
LG-15612

🛠 Summary of changes

Moves the reCAPTCHA script to the document head. Adds a new Yield area in the base html template so the script occurs before the stylesheets are loaded.

The intent is to optimize loading of the reCAPTCHA initializer to improve accuracy of scoring.

📜 Testing Plan

Prerequisite config settings
In application.yml set placeholder values for recaptcha_secret_key and recaptcha_site_key
To test if enterprise script loads set a value for recaptcha_enterprise_api_key and recaptcha_enterprise_project_id

  • Visit http://localhost:3000 and view page source.
  • View page source and see that the https://www.google.com/recaptcha/api.js script appears near the top just after the fonts are loaded and before the style sheets.
  • If enterprise key is added it should load https://www.google.com/recaptcha/enterprise.js
  • Ensure there are no regressions, errors and recaptcha still works.

@@ -1,5 +1,6 @@
<%= content_for(:head) do %>
<%= javascript_include_tag('init.js', nopush: false, integrity: 'sha256-eMXV2njRJxgQrFbuljRT/UTWePGrhl83bHHDDd+jFPw=') %>
<%= render CaptchaScriptComponent.new %>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think we want this on every page.

Copy link
Contributor

Choose a reason for hiding this comment

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

Did you try using content_for inside the existing component?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was right there in the Technical notes! 😢 I have now and it seems to be working smashingly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added to content_for with 7d1ac2b
Fixed up tests from slack conversation with 10eba3a

@kevinsmaster5 kevinsmaster5 marked this pull request as ready for review February 18, 2025 13:26
spec/views/devise/sessions/new.html.erb_spec.rb Outdated Show resolved Hide resolved
app/views/layouts/base.html.erb Outdated Show resolved Hide resolved
@kevinsmaster5 kevinsmaster5 force-pushed the kmas-lg-15612-load-reaptcha-script-earlier branch from 0d82c16 to 97755d0 Compare February 18, 2025 18:43
Copy link
Contributor

@aduth aduth left a comment

Choose a reason for hiding this comment

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

Tested with live reCAPTCHA in local environment and works as expected! 🚀

@kevinsmaster5 kevinsmaster5 merged commit 3475c26 into main Feb 18, 2025
2 checks passed
@kevinsmaster5 kevinsmaster5 deleted the kmas-lg-15612-load-reaptcha-script-earlier branch February 18, 2025 20:15
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