Are external scripts slowing down your WordPress site?
These are anything that pull information from outside your website: Google Fonts, Analytics, embedded YouTube videos, job postings, Gravatars, even comment and social sharing plugins.
You can optimize external scripts in WordPress by hosting files locally (fonts, analytics, Facebook Pixel), selectively disabling scripts using the Asset CleanUp plugin, and adding browser hints like preconnect and prefetch. Some plugins and scripts (eg AdSense) should generally be avoided if speed is important to you. Whatever is left over, determine whether the sacrifice in performance is worth it, and whether you should delete it or find an alternative.
External scripts are found in PageSpeed Insights or Reduce DNS Lookups in GTmetrix.
How To Optimize External Scripts In WordPress
- Find External Scripts
- Disable Unused Scripts, Styles, Plugins
- Preconnect, Prefetch, And Preload External Scripts
- Host Google Fonts Locally
- Host Google Analytics Locally
- Avoid Google AdSense At All Costs
- Only Use Google Maps On Contact Page
- Don’t Overtrack In Google Tag Manager
- Replace Social Media Posts With Screenshots
- Lazy Load YouTube Videos
- Disable Gravatars
- Disable Statistic Plugins
- Disable Broken Link Checker
- Disable Unused JetPack Modules
- Disable High CPU Social Share Plugins
- Disable And Replace Other High CPU Plugins
- Disable WooCommerce Scripts, Styles, Cart Fragments
- Disqus Conditional Load
- Selectively Load Contact Form 7
- Enable Caching For Facebook Pixel
- Configure Your Cache Plugin Properly
- CDNs Don’t Help
- Use Cloudflare Workers
- Run High CPU Tasks During Slow Times
1. Find External Scripts
Run your website through GTmetrix (the tool I recommend) and look at your PageSpeed and YSlow tab. If you expand items and see the same external script (or plugin) showing multiple times throughout your report, that probably means it’s slowing down your WordPress site. You can also use the GTmetrix Waterfall tab to find out how long each resource takes to load.
Query Monitor lets you see your slowest loading scripts, styles, and plugins:
2. Disable Unused Scripts, Styles, Plugins
Some plugins load across your entire website regardless of whether they’re being used.
Asset CleanUp lets you selectively disable unnecessary scripts, styles, and plugins from specific content. This can improve load times while reducing the number of HTTP requests. It also lets you host fonts locally, preconnect, preload, and disable unused WordPress features.
Install the plugin, edit a page, then disable any plugins or requests not used on that page:
Asset CleanUp Features:
- Disable unused scripts/plugins on certain content
- Preconnect, preload, combine, and host fonts locally
- Enable CDN URL rewrite to ensure files are optimized
- Disable embeds, dashicons, commonly unused features
- Disable XML-RPC Protocol Support partially or completely
- Optimize HTML by removing unnecessary code in the <head>
- Unload on 1 page, site-wide, by post type, or RegEx (premium feature)
Selectively Disable Plugins (Examples)
- Disable slider plugin on content without sliders
- Disable rich snippets plugin on content without rich snippets
- Disable contact form plugin on content without a contact form
- Disable AdSense or affiliate links where they aren’t being shown
- Disable social sharing plugin on all pages (since it’s usually for blog posts)
- Disable WooCommerce scripts, styles, cart fragments on non-eCommerce pages
3. Preconnect, Prefetch, And Preload External Scripts
For scripts that can’t be selectively disabled, preconnecting them helps browsers anticipate them. This won’t improve GTmetrix scores, but it can improve load times of external scripts.
Pre* Party Resource Hints supports DNS prefetch, prerender, preconnect, prefetch, and preload which are used as browser resource hints. All help load external resources faster and to my knowledge, WP Rocket only supports preloading and prefetching, but not preconnect.
Definitions (Credit: WP Rocket)
- Preconnect: tells browser to establish a connection to an external resource.
- Prefetch: tells browser to download anticipated files the user may request.
- DNS Prefetch: browser performs DNS lookups in background while user is browsing.
- Prerender: tells browser to download entire pages based on user browsing patterns.
- Preload: tells browser a navigation resource is needed and to fetch it ASAP.
Step 1: Copy all external domains you use on your website (find them in your GTmetrix and Query Monitor report), otherwise here’s a list of common domains to prefetch from Github:
Step 2: Add them to your Pre* Party Resource Hints plugin:
If you’re using WP Rocket, you can prefetch them (found in the Preload tab):
5. Host Google Fonts Locally
Hosting fonts locally should fix most font-related errors in GTmetrix.
But the best way to optimize fonts is to download them directly from the Google Fonts website, convert them to web font files using a tool like Transfonter, then add them to your CSS. Make sure you are minimal with the fonts and weights, as each one may add requests.
Step 1: Download your font(s) from Google Fonts.
Step 2: Convert them to web font files using Transfonter.
Step 3: Upload web font files to wp-content/uploads.
Step 4: Add custom fonts to your CSS.
Default URLs in stylesheet.css:
src: url('Roboto-Bold.woff2') format('woff2'),
Change these to:
src: url('http://yourwebsite.com/wp-content/uploads/fonts/Roboto-Regular.woff2') format('woff2'),
Step 5: Test the fonts in the WordPress text editor.
<h2 class="roboto_font"> Custom Font Test </h2>
<h2 class="roboto_bold_font"> Custom Font Test </h2>
6. Host Google Analytics Locally
7. Avoid Google AdSense At All Costs
Google AdSense is one of the most difficult external resources to optimize, and I recommend affiliate marketing instead since it doesn’t slow down your site, plus it’s more profitable and more personal. I usually hit 130k+/year with affiliate marketing so be sure to read that guide.
A gold product expert says:
“There are usually things that can be improved which is under your control, but ultimately, it’s a decision on a trade-off: does monetization make up for loss in speed?”
“This is why unless your income model revolves around 3rd-party advertisements, don’t put them on your WordPress site.”
Cloudflare Railgun is another option to optimize AdSense since it speeds up dynamic content.
8. Only Use Google Maps On Contact Page
Looks good, right?
Instead of embedding a Map, use an image with a link to driving directions.
If you do embeds, only use the Google Map on pages where you need them (contact page and those targeting a physical location). Never in your footer, widgets, or areas appearing sitewide.
9. Don’t Overtrack In Google Tag Manager
But the reality is, Google Tag Manager will probably slow down your site unless you have a large, unoptimized site that uses many third party scripts, in which case GTM may speed it up.
Avoiding common pitfalls and not using too many tags can help, but I don’t use GTM. In fact, I’ve honestly never tried it. But I do know that I’ve seen it in a lot of poor GTmetrix reports.
I also recommend the Google Tag Manager For WordPress plugin which only launches required tags for each page (speeding up load times of GTM) and makes the code easy to add.
10. Replace Social Media Posts With Screenshots
Embedded posts (eg. Tweets) can be replaced by screenshots.
It takes some time, but you can actually make these look really nice. Since these are images and don’t have to pull information from Twitter, they load much faster rather than embedding.
How I Did It
On my blog, I used a 2 column layout and measured each column to be 340 pixels (width). Next, I used the Zoom Chrome Extension combined with Awesome Screenshot to learn what zoom % I needed to get a good screenshot of the Tweet. I took screenshots of each Tweet, then cropped them to be exactly 340 pixels. Next, I compared all the screenshots to see which ones had similar height, then cropped or manipulated them so 2 screenshots had the same height. When you have 2 Tweets with the same width/height, they look great side-by-side in columns.
11. Lazy Load YouTube Videos
Embedded videos can easily add 2+ seconds to load times.
Videos can be optimized through lazy loading and by replacing the iframe with a preview image, so it’s only loaded once people click the play button (like the example video below).
Both can be done in WP Rocket:
WP YouTube Lyte is another good option and supports light YouTube embeds (only calling the “fat YouTube player” when you click the play button) and caching YouTube thumbnails locally.
Alternatively, this tutorial on light YouTube embeds can be used.
12. Disable Gravatars
If you have lots of blog comments, Gravatars can really slow down the post.
I ultimately decided to disable Gravatars which means no faces are shown in the comments. WP Rocket’s blog doesn’t use Gravatars either (just text). It can look somewhat boring but if speed is important, you may just want to style your comments with CSS and disable Gravatars. Gravatar cache plugins never worked for me, and I didn’t want to hide or break comments.
Here are a few options:
- Disable Gravatars (only show text, date, etc)
- Cache Gravatars using Optimum, Harrys, or FV (didn’t work for me)
- Break comments into several pages, so only a few Gravatars are showing
I don’t use Gravatars:
13. Disable Statistic Plugins
Are you using a plugin to collect statistics?
That will slow down your site, and you don’t need a plugin for this.
You can see everything you need in Google Analytics + Google Search Console without them slowing down your website. You don’t need JetPack, WP Statistics, or other statistics plugins.
14. Disable Broken Link Checker
Broken Link Checker runs ongoing scans which is why it’s banned with many hosts.
I still love this plugin and install/run it every few months. But after I’m done, I delete it immediately. You can also try Dr. Link Check which also scans for broken links across your entire website, but you can’t fix links directly in your WordPress dashboard like you can with Broken Link Checker. So either use it and delete it immediately after, or use Dr. Link Check.
15. Disable Unused JetPack Modules
First off, disable all JetPack modules you’re not using.
But why would you install a robust plugin if you’re only using a couple features? If you need stats, use Google Analytics, Cloudflare for a free CDN, UpdraftPlus for backups, WP Rocket for lazy loading, and for security, I would either use Wordfence, Sucuri, or iThemes Security.
You don’t need all those modules, let alone a bloated plugin.
Prioritize what features you need and install individual plugins for those. After all, that is the entire concept of lightweight themes (buy a theme with minimal features and rely on plugins to add those you need). Don’t install a bloated theme or plugin and be stuck with loss in speed.
Step 1: Head to your JetPack dashboard, scroll down, and click Debug.
Step 2: Access the full list of JetPack modules available on your WordPress site.
Step 3: Deactivate all modules you’re not using.
16. Disable High CPU Social Share Plugins
Social sharing buttons have to pull share counts from Facebook, Twitter, etc.
If your plugin has an option to update these periodically or during off-peak times, this is much better than updating these counts in real-time. However, you probably just want to know which social sharing plugins are the fastest and most lightweight, so here are a few of them.
Recommended (Lightweight) Social Sharing Plugins:
- Social Sharing Plugin
- Social Media Share Buttons (Mashable)
- Social Sharing For WordPress
- AddToAny Share Buttons
- WP Social Sharing
- Easy Social Share
17. Disable And Replace Other High CPU Plugins
There’s a reason WP Engine, GoDaddy, and other hosts blacklist certain types of plugins.
Most slow WordPress plugins include social sharing, statistic, slider, backup, page builders, calendar, chat, contact form, portfolio, related post, sitemap, Wordfence, WPML, WooCommerce, JetPack, and plugins that run ongoing scans or processes. Slow plugins can be found using Query Monitor or in your GTmetrix Waterfall report.
- AdSense Click Fraud Monitoring
- All-In-One Event Calendar
- Backup Buddy
- Beaver Builder
- Better WordPress Google XML Sitemaps
- Broken Link Checker
- Constant Contact for WordPress
- Contact Form 7
- Contextual Related Posts
- Digi Auto Links
- Disqus Comment System
- Divi Builder
- Facebook Chat
- Fancy Gallery
- Fuzzy SEO Booster
- Google Analytics
- Google Language Translator
- View Full List Of 65 Slow WordPress Plugins
18. Disable WooCommerce Scripts, Styles, Cart Fragments
All WooCommerce sites come with extra scripts, styles, and cart fragments.
These load across your entire website – even on non-WooCommerce pages. Cart fragments alone can take up to 10 seconds to load. On top of the 3 WooCommerce stylesheets and multiple scripts generated by WooCommerce (and the fact that WooCommerce sites usually requires more plugins), it’s no wonder most of these sites typically have slow page load times.
Option 1: Asset CleanUp
Selectively disable WooCommerce functions on pages where they don’t need to be loaded.
Option 2: Use Code From Github
Disable WooCommerce Scripts: add this code functions.php:
Disable WooCommerce Styles: see WooCommerce’s tutorial.
Disable WooCommerce Cart Fragments: add this code to funtions.php:
Option 3: Perfmatters
Kinsta’s Perfmatters plugin lets you disable all these in 1-click, plus has many other features to optimize your site like disabling unnecessary WordPress functions. I use it on my own website.
19. Disqus Conditional Load
Disqus and many comment plugins can create external requests.
Disqus Conditional Load is an advanced version of Disqus which includes lazy loading and script disabling. If Disqus is creating requests in your GTmetrix report, this can fix most them.
20. Selectively Load Contact Form 7
You can also use Asset CleanUp to disable contact forms on pages that don’t use them:
21. Enable Caching For Facebook Pixel
WP Rocket’s Facebook Pixel add-on lets you apply browsing caching for Facebook Pixel.
This is the only way to optimize Facebook Pixel to my knowledge, which lets you track who is coming to your website and follow up with them using Facebook Ads, among other features.
22. Configure Your Cache Plugin Properly
Even though it’s so important, most people don’t configure their cache plugin properly.
I personally use WP Rocket because it comes with many features most cache plugins don’t (hosting fonts, analytics, and Facebook Pixel locally, lazy loading images + videos, database cleanup, preloading, heartbeat control, and integration of both Cloudflare and multiple CDNs like StackPath). Otherwise, you may have to install 7 extra plugins to get those optimizations.
Cache Plugin Tutorials:
- The Ideal WP Rocket Settings With Cloudflare + CDN
- The Ideal WP Fastest Cache Settings With Cloudflare + CDN
- The Ideal Swift Performance Settings With Cloudflare + CDN
- The Ideal W3 Total Cache Settings With Cloudflare + CDN
- The Ideal WP Super Cache Settings With Cloudflare + CDN
23. CDNs Don’t Help
CDNs are great for optimizing files on your WordPress site.
But as far as external scripts, it won’t help. I even messaged StackPath who said while CDNs help with many other things, external scripts aren’t one of them. It makes sense – how can you offload something that’s not even hosted your website? Oh well, at least they were honest.
I still recommend Cloudflare and StackPath since they help tremendously with offloading resources to their data centers (making your server more relaxed) and using features like Cloudflare Page Rules, Hotlink Protection, and their security features to both speed up and protect your website. And more CDNs means more data centers to host your files on, meaning even faster delivery of your content. That’s why I use both Cloudflare and StackPath’s CDNs.
24. Use Cloudflare Workers
25. Run High CPU Tasks During Slow Times
Backups, Broken Link Checker, and other high CPU tasks should run during slow times. Simple.
Frequently Asked Questions
✅ How do I find which third party scripts slow down my site?
These will usually appear in the Reduce DNS Lookups section in the GTmetrix YSlow tab. Some of the most common third party scripts are Google Fonts, Analytics, Maps, AdSense, Google Tag Manager, social media requests, embedded YouTube videos, and Gravatars.
✅ How do I optimize Google Fonts?
Combining Google Fonts and hosting them locally is the best way to make fonts load faster. You can also prefetch and preconnect your fonts. Try using the OMGF plugin.
✅ What about social media errors in GTmetrix?
These are usually caused by social sharing buttons, social media widgets, or any other social media element on your site. These can usually NOT be optimized - the most important part is to choose a lightweight social sharing plugin, if you decide to use one.
✅ How to fix the Leverage Browser Caching issue for Google Analytics?
You can try hosting your Google Analytics tracking code locally either through WP Rocket (or whatever cache plugin you're using) or the CAOS Analytics plugin. However, fixing this error usually won't directly improve load times.
✅ Can I make embedded YouTube videos load faster?
Yes, plugins like WP Rocket or WP YouTube Lyte let you lazy load videos and replace the iframe with a preview image. This can shave multiple seconds of the content's load time.
How Is Your GTmetrix Report Now?
My homepage is 100% but my posts are usually more impressive.
I’ll take a 1.7s load time on a 6.28MB page with 196 requests any day.
Originally, the external scripts slowing down my site were Google Fonts, Google Analytics, embedded YouTube videos, embedded Tweets, and I had some problems configuring StackPath’s CDN. But once I implemented the steps in this post (and sacrificed a plugin or two), my entire WordPress site usually loads ridiculously fast. Cloudways hosting also helped.
The main thing holding this post back from 100% are those embedded Github codes. But hey, you can’t always be perfect, and at least I have Github in my preconnected and prefetched list!
Leave me a comment or contact our team about our WordPress speed service.