manifest / performance / cf7-asset-optimizer
CF7 Asset Optimizer
Only loads Contact Form 7 scripts and styles on pages that contain a form. Fixes CF7 #1278.
by Renzo Johnson · github.com/renzojohnson/cf7-asset-optimizer · website
★ 0stars
0forks
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/renzojohnson/cf7-asset-optimizer/archive/refs/heads/main.zipAlso on Packagist as renzojohnson/cf7-asset-optimizer:
composer require renzojohnson/cf7-asset-optimizerFrom the readme
CF7 Asset Optimizer
Only loads Contact Form 7 scripts and styles on pages that actually contain a form. Zero configuration.
Fixes Contact Form 7 #1278 — CF7 enqueues its JS, CSS, reCAPTCHA, Turnstile, and Stripe scripts on every single page, even pages with no form. This plugin detects whether the current page has a CF7 form and dequeues all CF7 assets when no form is present.
Author: Renzo Johnson
Requirements
- PHP 8.4+
- WordPress 6.4+
- Contact Form 7 5.0+
Installation
Via Composer
Manual
Download and upload to /wp-content/plugins/cf7-asset-optimizer/, then activate.
As mu-plugin
Copy cf7-asset-optimizer.php to /wp-content/mu-plugins/.
How It Works
The plugin hooks into CF7's own wpcf7loadjs and wpcf7loadcss filters to conditionally disable asset loading. On pages without a form, it also dequeues module scripts (reCAPTCHA, Turnstile, Stripe, SWV).
Detection
The plugin checks for CF7 forms in:
- [contact-form-7] shortcode in post content
- [contact-form] shortcode (legacy alias)
- contact-form-7/contact-form-selector Gutenberg block
- CF7 widgets in sidebar areas
- CF7 shortcodes inside text widgets
- CF7 blocks inside block widgets
Assets Dequeued
When no form