Skip to content
Insights

Lighter websites

Contact Forms and CAPTCHA: Load Them Only Where Needed

Form plugins and CAPTCHA scripts can load on every page, not just the one with the form. How to spot them, and keep them where the form actually is.

Sol Rudd6 min read

Diagram: two rows of five page cards; in the top row every page carries an amber script block, in the bottom row only the contact page with form fields keeps its script

Most small business sites have one contact form, often on one page. Yet the files that run that form, and the CAPTCHA that keeps spam out of it, can load on the home page, every blog post and the privacy policy too. This article shows how to find out whether that is happening on your site, what the CAPTCHA providers themselves recommend, and how to keep these files to the pages that need them.

How a form ends up on every page

A form plugin or theme adds its own scripts and styles to the page. If it adds them site-wide, every page carries them, form or no form. A CAPTCHA adds more: a script fetched from the provider's own servers.

You may see async or defer on these scripts and assume they are taken care of. MDN's script element reference explains that both attributes let the browser fetch the script while it keeps reading the page. They change when it runs, not whether it runs: an async script runs as soon as it arrives, and a long one can still hold up the page while it does; a defer script waits until the page has been read. Neither stops it from being downloaded.

A carbon test counts what loads on the first visit without any clicks. GreenTracer measures one initial, uncached load with Google PageSpeed Insights, and under the Sustainable Web Design Model v4 every 100 kB removed from that load lowers a page's estimate by about 0.015 g CO₂e per page view (about 0.012 g on a host listed as green). Small per view, but repeated on every page that didn't need the files.

Check your own site in five minutes

We won't quote typical sizes here, because they vary by plugin, provider and version. Measure your own instead, using the Network panel in Chrome DevTools (the Network reference covers each step):

  1. Open a page that has no form, such as a blog post, in a private window. Open DevTools, go to Network, tick “Disable cache” and reload.
  2. Type your form plugin's name, or the CAPTCHA provider's domain, into the filter box: for example recaptcha for Google reCAPTCHA or challenges.cloudflare.com for Turnstile. DevTools matches against the request URL and domain.
  3. If anything appears, note each file's size in the Size column. Clear the filter afterwards to see the page's total in the status bar at the bottom.
  4. Repeat on the home page and on the contact page, so you know where the files are genuinely needed.

For a fuller walk through of the Network panel, see how to check your page weight.

What the CAPTCHA providers say

Before removing anything, read your provider's guidance, because it doesn't always point the same way.

  • Google reCAPTCHA v3 scores visitors in the background. Its documentation says it “works best when it has the most context about interactions with your site” and recommends running it in the background of pages as well as on forms. So with v3, loading it only on the contact page is a trade-off you should make knowingly. That page now carries a notice that it is deprecated and points to Google Cloud documentation, so check the current guidance for your setup.
  • Google reCAPTCHA v2 (the “I'm not a robot” box) supports explicit rendering: you load the script with render=explicit and an onload callback, then draw the widget when you choose.
  • Cloudflare Turnstile also offers explicit rendering, but recommends executing its script “as early upon the visitor's page entry as possible”. It also warns that its script must be loaded from Cloudflare's exact URL: proxying or caching it will break Turnstile when it is updated. Don't bundle it into your own files.

Four ways to keep them where the form is

  • Look for a plugin setting. Check your form plugin's own documentation for a setting that loads its files only on pages that contain a form. If one exists, use it before reaching for custom code.
  • Remove them in code on other pages (WordPress). WordPress's conditional tags such as is_page() tell you which page is showing, and wp_dequeue_script and wp_dequeue_style remove files that were already queued. A developer can use them like this, with the plugin's real file handles in place of the example:
add_action( 'wp_enqueue_scripts', function () {
  if ( ! is_page( 'contact' ) ) {
    wp_dequeue_script( 'example-form-script' );
    wp_dequeue_style( 'example-form-style' );
  }
}, 100 ); // run late, after the plugin has queued its files
  • Load the CAPTCHA when someone starts the form. With explicit rendering, the CAPTCHA script can be added when a visitor first clicks into the form, rather than on page load. This matches the W3C's draft Web Sustainability Guidelines, which suggest loading third-party content only when the user interacts with it. Weigh it against your provider's advice above.
  • Link to the form instead of repeating it. If a short form sits in the footer of every page, consider a clear “Contact us” link to one contact page. The same guideline suggests “linking to a form instead of embedding a widget”.

The same thinking applies to other third-party tools; see maps, chat and embeds on demand and finding unused JavaScript.

Test before you call it done

  1. Repeat the DevTools check on a page without a form: the filtered requests should be gone.
  2. On the contact page, fill in and send a real test message, on a phone and a desktop, and confirm it arrives. A form that looks fine but can't submit is worse than a heavy one.
  3. Keep an eye on spam for a few weeks, especially if you changed how a background CAPTCHA loads.
  4. Check the page again and compare the bytes measured with the earlier report, which is kept as history.

Sources

All articles

Check your own site

See the estimated carbon of one page view on your page, its grade, and whether your host is listed as green. It's free.

Check a website