=== Speed up Contact Form 7 ===
Contributors: hellafast
Tags: contact form 7, pagespeed, performance, optimize, recaptcha
Requires at least: 5.0
Tested up to: 7.1
Requires PHP: 7.0
Stable tag: 1.2.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Loads Contact Form 7, reCAPTCHA, Turnstile and add-on assets only on pages that actually show a form.

== Description ==

Contact Form 7 loads its JavaScript and CSS on every page of your site, even pages without a form. So do reCAPTCHA, Cloudflare Turnstile and many CF7 add-ons. That's unused CSS and JavaScript on almost every page, and PageSpeed notices.

This plugin keeps all of that off pages that don't have a form.

* Zero settings. Activate it and you're done.
* Detects forms added with the `[contact-form-7]` shortcode or the Contact Form 7 block.
* Also holds back reCAPTCHA v3, Cloudflare Turnstile, Stripe and any add-on script or style that depends on Contact Form 7.
* Safety net: if a form shows up somewhere it couldn't detect in advance (a widget, page builder, block theme template, `do_shortcode()` call), the assets load automatically for that page, so the form keeps working.
* Uses Contact Form 7's own `wpcf7_load_js` / `wpcf7_load_css` switches and respects them if you already turned them off.

Need help with website speed optimization? Visit [hellafast.digital/speed-optimization-service](https://hellafast.digital/speed-optimization-service/). We've been doing it for years.

== Installation ==

1. Install and activate Contact Form 7.
2. Install and activate this plugin.

That's it. It has been tested on dozens of client websites, but check your contact forms after activating it, just in case :)

== Frequently Asked Questions ==

= My form is inside a popup or loaded with AJAX and stopped working =

The plugin can't see forms that are injected after the page loads. Force the assets on for those pages:

`add_filter( 'sucf7_load_assets', function ( $load ) {
	return $load || is_front_page();
} );`

= How do I hold back another add-on's script or style? =

Add-on assets that depend on Contact Form 7 are handled automatically. For others, add their handles:

`add_filter( 'sucf7_extra_handles', function ( $handles ) {
	$handles['scripts'][] = 'my-addon-script';
	$handles['styles'][]  = 'my-addon-style';
	return $handles;
} );`

= Does reCAPTCHA v3 still protect my forms? =

Yes. reCAPTCHA still loads on every page with a form. Google recommends loading v3 site-wide so it can see more of a visitor's behavior, so scores may be slightly less accurate. If you'd rather keep it everywhere, remove `google-recaptcha` and `wpcf7-recaptcha` from the list with the `sucf7_extra_handles` filter.

== Changelog ==

= 1.2.0 =
* Tested with WordPress 7.1 and Contact Form 7 6.x.
* Uses Contact Form 7's built-in `wpcf7_load_js` / `wpcf7_load_css` switches instead of dequeuing after the fact.
* Detects the Contact Form 7 block and the `[contact-form]` shortcode alias.
* Holds back Cloudflare Turnstile, Stripe, the SWV validation script and any add-on asset that depends on Contact Form 7.
* New: forms in widgets, page builders and templates keep working (assets load automatically when a form is rendered).
* New filters: `sucf7_load_assets`, `sucf7_extra_handles`.
* Fixed the readme "Stable tag".

= 1.1 =
* Support for the Redirection for Contact Form 7 add-on.

= 1.0 =
* Initial release.
