WordPress plugins dequeueing #2
Contact Form 7 - Too many assetsHey, it’s me again. If you don’t know what this post is about, you can read my first post. I explained everything there.
Today we’re going to take a look at the Contact Form 7 plugin with over 5 million installs.
Contact Form 7 – wp repository
version 5.6.4
- Style
- contact-form-7 (contact-form-7/includes/css/styles.css)
- contact-form-7-rtl (contact-form-7/includes/css/styles-rtl.css)
- Script
- contact-form-7 (contact-form-7/includes/js/index.js)
- swv (contact-form-7/includes/swv/js/index.js)
We can see that after plugin activation three assets are loaded on frontpage. One css file and two javascripts. When we checked the code, we can see another style will be loaded, if you enable RTL (right to left). All these assets are loaded without even creating a form. That’s quite a lot just for activation of the plugin. And keep in mind that all of these files will load even on pages that don’t have a form.
Best solution for this plugin is to enqueue scripts and styles only if form is printed. Otherwise they are unnecesarry.
Let’s see what the plugin authors say 🙂
See you with the next one
Question for the readers: Would you like me to write code here that removes these assets and adds them only when needed?