25 External Scripts To Optimize In WordPress: Speed Up Fonts, Analytics, YouTube Videos, WooCommerce, Third Party Scripts

Home » WordPress Speed Tips & Tricks » 25 External Scripts To Optimize In WordPress: Speed Up Fonts, Analytics, YouTube Videos, WooCommerce, Third Party Scripts

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 almost always show errors in GTmetrix under Reduce DNS Lookups:

WordPress External Scripts

Here’s how to optimize third party scripts:

How To Optimize External Scripts In WordPress

  1. Find External Scripts
  2. Disable Unused Scripts, Styles, Plugins
  3. Preconnect, Prefetch, And Preload External Scripts
  4. Defer Parsing Of JavaScript
  5. Host Google Fonts Locally
  6. Host Google Analytics Locally
  7. Avoid Google AdSense At All Costs
  8. Only Use Google Maps On Contact Page
  9. Don’t Overtrack In Google Tag Manager
  10. Replace Social Media Posts With Screenshots
  11. Lazy Load YouTube Videos
  12. Disable Gravatars
  13. Disable Statistic Plugins
  14. Disable Broken Link Checker
  15. Disable Unused JetPack Modules
  16. Disable High CPU Social Share Plugins
  17. Disable And Replace Other High CPU Plugins
  18. Disable WooCommerce Scripts, Styles, Cart Fragments
  19. Disqus Conditional Load
  20. Selectively Load Contact Form 7
  21. Enable Caching For Facebook Pixel
  22. Configure Your Cache Plugin Properly
  23. CDNs Don’t Help
  24. Use Cloudflare Workers
  25. Run High CPU Tasks During Slow Times

 

1. Find External Scripts

GTmetrix
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.

WordPress External Scripts

Query Monitor
Query Monitor lets you see your slowest loading scripts, styles, and plugins:

Query Monitor Scripts

Query Monitor Slow 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:

External Third Party Scripts

Disable WordPress External Scripts

Asset CleanUp Features:

  • Disable unused scripts/plugins on certain content
  • Minify, combine, defer, and cache CSS + JavaScript
  • 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:

Pre Party Resource Hints

If you’re using WP Rocket, you can prefetch them (found in the Preload tab):

Prefetch-DNS-Requests

 

4. Defer Parsing Of JavaScript

Defer parsing of JavaScript tells browsers to wait to download JavaScript until after everything else is downloaded.

If you’re using WP Rocket, enable Load JavaScript Deferred in the File Optimization tab:

Load JavaScript Deferred

If your cache plugin doesn’t support this, you can use the Async JavaScript plugin:

Async JavaScript

 

5. Host Google Fonts Locally

Hosting fonts locally should fix most font-related errors in GTmetrix.

You can do this using Self-Hosted Google Fonts, OMGF, or Asset CleanUp.

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.

Google-Fonts-GTmetrix

Step 1: Download your font(s) from Google Fonts.

Step 2: Convert them to web font files using Transfonter.

Transfonter-Google-Font-Conversion

Step 3: Upload web font files to wp-content/uploads.

Example:

  • http://yourwebsite.com/wp-content/uploads/fonts/Roboto-Regular.woff
  • http://yourwebsite.com/wp-content/uploads/fonts/Roboto-Regular.woff2
  • http://yourwebsite.com/wp-content/uploads/fonts/Roboto-Bold.woff
  • http://yourwebsite.com/wp-content/uploads/fonts/Roboto-Bold.woff2

Step 4: Add custom fonts to your CSS.

Default URLs in stylesheet.css:
src: url('Roboto-Bold.woff2') format('woff2'),
url('Roboto-Bold.woff') format('woff');

Change these to:
src: url('http://yourwebsite.com/wp-content/uploads/fonts/Roboto-Regular.woff2') format('woff2'),
url('http://yourwebsite.com/wp-content/uploads/fonts/Roboto-Regular.woff') format('woff');

Step 5: Test the fonts in the WordPress text editor.

<h2>Testing</h2>
<h2 class="roboto_font"> Custom Font Test </h2>
<h2 class="roboto_bold_font"> Custom Font Test </h2>

 

6. Host Google Analytics Locally

If you see a leverage browser caching issue, hosting your Google Analytics tracking code locally will fix this. You can use WP Rocket’s Google Tracking, CAOS Analytics, or WP Disable.

Leverage-Brower-Caching-Google-Analytics

 

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?”

Kinsta says:

“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.

Cloudflare Railgun

 

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.

Google Map

 

9. Don’t Overtrack In Google Tag Manager

Some will argue that Google Tag Manager can actually speed up your website, since it takes all the Javascript on your site and replaces it with one single script, which is triggered from GTM.

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.

Google Tag Manager Speed

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.

2019 Hosting Poll

2017-WordPress-Hosting-FB-Poll

Elementor Hosting Recommendations

July 2019 Hosting Recommendation

2016-WordPress-Hosting-FB-Poll

Favorite Hosting For Elementor

2018 Hosting Recommendations

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.

And yes, I recommend SiteGround for hosting or Cloudways / Kinsta. There’s a lot of bad hosting reviews out there; look at the Facebook polls and you will see who the winners are.

 

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-Rocket-Lazy-Load

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:

Comment Without 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.

Google Search Console Performance Dashboard

 

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.

JetPack Debug

Step 2: Access the full list of JetPack modules available on your WordPress site.

JetPack Modules Access

Step 3: Deactivate all modules you’re not using.

JetPack Modules

 

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.

Social Sharing Plugin Requests

Recommended (Lightweight) Social Sharing Plugins:

 

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.

  1. AddThis
  2. AdSense Click Fraud Monitoring
  3. All-In-One Event Calendar
  4. Backup Buddy
  5. Beaver Builder
  6. Better WordPress Google XML Sitemaps
  7. Broken Link checker (use Dr. Link Check)
  8. Constant Contact for WordPress
  9. Contact Form 7
  10. Contextual Related Posts
  11. Digi Auto Links
  12. Disqus Comment System
  13. Divi Builder
  14. Essential Grid
  15. Facebook Chat
  16. Fancy Gallery
  17. Fuzzy SEO Booster
  18. Google Analytics
  19. Google Language Translator
  20. 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.

WooCommerce Cart Fragments

Option 1: Asset CleanUp
Selectively disable WooCommerce functions on pages where they don’t need to be loaded.

Asset CleanUp WooCommerce

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.

perfmatters woocommerce optimization

 

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.

Disqus Conditional Load

 

20. Selectively Load Contact Form 7

Although I’m not a big fan of Contact Form 7 because of it’s slow load times, you can load JavaScript + Contact Form 7 stylesheet only on pages that use contact forms. Otherwise, they will load on every single page. I suggest Gravity Forms or another form plugin that is faster.

You can also use Asset CleanUp to disable contact forms on pages that don’t use them:

Asset CleanUp Selective Disable

 

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.

Facebook Pixel Browser Caching

 

22. Configure Your Cache Plugin Properly

Even though it’s so important, most people don’t configure their cache plugin properly.

Many GTmetrix errors may be related to things your cache plugin can handle (minifying and combining files, deferring JavaScript, caching, adding expires headers, video optimization, serving files from a CDN, and hosting Google Fonts + Analytics locally). Since different cache plugins come with different features, you should go through all your settings and test them vigorously, checking how enabling features may result in faster load times and better scores.

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:

WP Rocket File Optimization

 

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

Workers is a JavaScript execution environment that allows developers to augment existing applications or create new ones without configuring or maintaining infrastructure. Pricing is $5/month + usage (first 10 million Worker-powered requests are free, then $.50 per million requests). Workers can be configured to run specific pages, subdomains, etc. Test it out here.

 

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.

2019 GTmetrix Report

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!

Need help?

Leave me a comment or contact our team about our WordPress speed service.

Cheers,
Tom

View More Tutorials

Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments