PHPackages                             renzojohnson/cf7-asset-optimizer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. renzojohnson/cf7-asset-optimizer

ActiveWordpress-plugin[Utility &amp; Helpers](/categories/utility)

renzojohnson/cf7-asset-optimizer
================================

Only loads Contact Form 7 scripts and styles on pages that contain a form. Performance optimization for CF7.

v1.0.0(4mo ago)00MITPHPPHP ^8.4

Since Feb 24Pushed 2mo agoCompare

[ Source](https://github.com/renzojohnson/cf7-asset-optimizer)[ Packagist](https://packagist.org/packages/renzojohnson/cf7-asset-optimizer)[ Docs](https://renzojohnson.com)[ RSS](/packages/renzojohnson-cf7-asset-optimizer/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (1)Versions (2)Used By (0)

CF7 Asset Optimizer
===================

[](#cf7-asset-optimizer)

[![Latest Version](https://camo.githubusercontent.com/ac70004b6113da9e5a443174010f4dc150c47537042ef5566b40a4426fc73929/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f72656e7a6f6a6f686e736f6e2f6366372d61737365742d6f7074696d697a65722e737667)](https://packagist.org/packages/renzojohnson/cf7-asset-optimizer)[![PHP Version](https://camo.githubusercontent.com/8333f7450e233c5d887d20d9a26159435626bc75066230f1d66ed7086a771016/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f72656e7a6f6a6f686e736f6e2f6366372d61737365742d6f7074696d697a65722e737667)](https://packagist.org/packages/renzojohnson/cf7-asset-optimizer)[![License](https://camo.githubusercontent.com/f77448055ff52e5913ab1d426f148ddd4c0431ffca963a1c30bc3450c68a9c54/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f72656e7a6f6a6f686e736f6e2f6366372d61737365742d6f7074696d697a65722e737667)](https://github.com/renzojohnson/cf7-asset-optimizer/blob/main/LICENSE)

Only loads Contact Form 7 scripts and styles on pages that actually contain a form. Zero configuration.

Fixes [Contact Form 7 #1278](https://github.com/rocklobster-in/contact-form-7/issues/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](https://renzojohnson.com)

Requirements
------------

[](#requirements)

- PHP 8.4+
- WordPress 6.4+
- Contact Form 7 5.0+

Installation
------------

[](#installation)

### Via Composer

[](#via-composer)

```
composer require renzojohnson/cf7-asset-optimizer

```

### Manual

[](#manual)

Download and upload to `/wp-content/plugins/cf7-asset-optimizer/`, then activate.

### As mu-plugin

[](#as-mu-plugin)

Copy `cf7-asset-optimizer.php` to `/wp-content/mu-plugins/`.

How It Works
------------

[](#how-it-works)

The plugin hooks into CF7's own `wpcf7_load_js` and `wpcf7_load_css` filters to conditionally disable asset loading. On pages without a form, it also dequeues module scripts (reCAPTCHA, Turnstile, Stripe, SWV).

### Detection

[](#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

[](#assets-dequeued)

When no form is detected, these handles are dequeued:

HandleSource`contact-form-7`Main CF7 JS`contact-form-7-html5-fallback`Datepicker fallback`swv`Schema-based Validation`wpcf7-recaptcha`reCAPTCHA v3 handler`google-recaptcha`Google reCAPTCHA API`cloudflare-turnstile`Cloudflare Turnstile API`wpcf7-stripe`Stripe JS`contact-form-7` (style)Main CF7 CSS`contact-form-7-rtl` (style)RTL CSS`jquery-ui-smoothness` (style)jQuery UI theme`wpcf7-stripe` (style)Stripe CSS### Edge Cases

[](#edge-cases)

For forms rendered via PHP templates or dynamic shortcodes not in post content:

```
// Force-load CF7 assets on specific pages
add_filter('cf7ao_has_form', function (?bool $has_form): ?bool {
    if (is_page('custom-form-page')) {
        return true;
    }
    return $has_form;
});
```

Testing
-------

[](#testing)

```
composer install
vendor/bin/phpunit
```

Related Project
---------------

[](#related-project)

If you use Contact Form 7 with Mailchimp, check out [Chimpmatic](https://chimpmatic.com) — a CF7-to-Mailchimp integration plugin with 50,000+ active installations. Supports merge field mapping, subscriber tags, groups, double opt-in, and GDPR consent. Built by the same developer.

- [Chimpmatic — Connect Contact Form 7 to Mailchimp](https://chimpmatic.com)
- [How to Get Your Mailchimp API Key](https://chimpmatic.com/how-to-get-your-mailchimp-api-key)

Links
-----

[](#links)

- [Packagist](https://packagist.org/packages/renzojohnson/cf7-asset-optimizer)
- [GitHub](https://github.com/renzojohnson/cf7-asset-optimizer)
- [Issues](https://github.com/renzojohnson/cf7-asset-optimizer/issues)
- [CF7 Issue #1278](https://github.com/rocklobster-in/contact-form-7/issues/1278)
- [Author](https://renzojohnson.com)

License
-------

[](#license)

MIT License. Copyright (c) 2026 [Renzo Johnson](https://renzojohnson.com).

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance81

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

128d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6e1b69733e3d1fd486158d322c23d99281623046b3c357529c9930e50d73fcda?d=identicon)[renzo.johnson](/maintainers/renzo.johnson)

---

Top Contributors

[![renzojohnson](https://avatars.githubusercontent.com/u/4695400?v=4)](https://github.com/renzojohnson "renzojohnson (3 commits)")

---

Tags

asset-loadingcf7composercontact-form-7optimizationperformancephpwordpresswpcf7wordpressperformanceoptimizationwpcf7contact-form-7cf7dequeueasset-loadingpage-speed

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/renzojohnson-cf7-asset-optimizer/health.svg)

```
[![Health](https://phpackages.com/badges/renzojohnson-cf7-asset-optimizer/health.svg)](https://phpackages.com/packages/renzojohnson-cf7-asset-optimizer)
```

###  Alternatives

[nilportugues/php_backslasher

Adds all PHP internal functions to its namespace by adding backslash to them. Improves the application's performance when OPCache is on.

889.4k20](/packages/nilportugues-php-backslasher)[wp-media/imagify-plugin

Image optimization plugin for WordPress by WP Media.

8067.5k](/packages/wp-media-imagify-plugin)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
