Here’s what you’ll learn in this article:
If you just want to skip straight to the tutorial, you can click the last link in the list above.
But…what does that actually mean? And why is it an important performance consideration?
Basically, when someone visits your WordPress site, your site’s server delivers the HTML contents of your website to that visitor’s browser.
By speeding up your content’s above-the-fold load times, you make Google happy and create a better, speedier experience for your visitors.
GTmetrix will give you a grade and also list out specific scripts that need to be deferred:
With defer, visitors’ browsers will still download the scripts while parsing the HTML, but they will wait to parse the script until after the HTML parsing has been completed.
This graphic from Growing with the Web does a great job of explaining the difference:
- Varvy method – if you’re tech-savvy, you can edit your site’s code directly and use the code snippet from Varvy.
- Functions.php file – you can add a code snippet to your child theme’s functions.php file to automatically defer scripts.
You can click above to jump straight to your preferred method or read through all the techniques to find the one that’s best for you.
At the top, you can enable the plugin’s functionality and choose between async and defer. Remember:
Further down, you can also choose how to handle jQuery. A lot of themes and plugins rely heavily on jQuery, so if you try to defer parsing the jQuery scripts you might break some of your site’s core functionality. The safest approach is to exclude jQuery, but you can experiment with deferring it. Just make sure to test your site thoroughly.
Further down, you can also manually include or exclude specific scripts from being deferred, including a nice user-friendly feature to let you target specific themes or plugins that are active on your site:
2. Use the WP Rocket Plugin
You can implement this method by tweaking the code snippet that Varvy supplies and then adding the script to your theme immediately before the closing