Resource
Defer Gravity Forms script load
Conditionally enqueue GF assets only on pages that contain a form. -120 KB on every other page.
Conditionally enqueue Gravity Forms assets only on pages that contain a form. -120 KB on every other page.
What’s in it
A functions.php / mu-plugin snippet that hooks wp_enqueue_scripts and checks the current post’s content for a [gravityform] shortcode before enqueueing the GF scripts. Pages without a form don’t load the 120 KB of GF assets.
Why this matters
Gravity Forms eagerly enqueues its scripts site-wide by default. On a 50-page B2B marketing site with one contact form, that’s 49 pages shipping unused JS. This snippet measures a 0.3 — 0.6s LCP improvement on those pages.
License
MIT.