How Do I Speed Up Scripts Like GA and FB Pixel On WordPress?

Authored By: James LePage
Published On: July 10, 2020

Affiliate Disclosure: Some links on this website are affiliate links. We make commissions for purchases made through those links.

We only recommend items/tools that we've personally used and like.

Full Disclosure | FTC Statement

amazon elementor E book

In this article, we're going to introduce a method that we use to speed up Third Party JavaScript on our WordPress websites.

You can usually identify the impact that third party scripts are having on your website loading times by using a tool such as Google PageSpeed or GT metrics.

If a script is severely impacting the page speed loading time, Google PageSpeed will identify the opportunity “Reduce The Impact Of 3rd Party JS” and tell you how much quicker your website would load if you addressed these issues. it will also tell you the actual scripts in question. Taking a look at the waterfall report on GTMetrix and identifying JavaScript files that are being loaded from third party locations would help you isolate third party scripts that could be optimized.

This is a common Reddit question

What Are Some Typical Culprits?

The usage of 3rd party JavaScript is highly dependent on your website, but there are some typical scripts that impact the loading time.

  • FB Pixel: Facebook Pixel is a fairly large script that is used to track visitors coming from Facebook and ending up on your website.
  • Google Analytics: Google Analytics is one of the most popular third party JavaScript integrations to a WordPress website and will be identified by Google PageSpeed as something that is slowing your site down.
  • HubSpot CRM: HubSpot will integrate with your WordPress website and automatically track all leads period to do this it uses JavaScript (Which on your website is considered third party).
  • Stripe: If you're processing payments with Stripe, it'll load a JavaScript file throughout your website.
  • PayPal: If you're processing payments with PayPal, it too will load a JavaScript file throughout your website.

There are many other third party JavaScript libraries that will impact the loading time of your website. In most instances, if you're calling third party, PageSpeed will tell you that reducing the impact of it loading on your website will speed up your time and improve your score. Additional third party scripts that impact your websites loading time could come from ad networks, or further integrations.

Once you've identified the third party JavaScript that is impacting the loading time of your website, it's time to resolve this. There are two tools that we're going to use to help reduce the impact of 3rd party JavaScript loading on our WordPress website.

Reduce the impact of 3rd party JavaScript on WordPress

Flying Scripts

The first major tool is is a plugin called flying scripts. This is a simple plugin that downloads and runs JavaScript on user interaction.

In English, this means that a third party script will not impact the loading time of your website because it isn't downloaded automatically. Instead, the script will be downloaded on the website when a user scrolls or clicks.

You should only do this for noncritical JavaScript. By not initially loading all JavaScript, and only focusing on the critical scripts necessary to loading the initial viewport of the page, you reduce the load on the server (less HTTP requests), And you give more resources to the loading of critical JavaScript resulting in a faster page speed time, better speed index, and lower time to interactive.

This is different than defer because (noncritical) scripts simply are not loaded unless a user interacts with the page.

The back end of this plugin is extremely simple and easy to use. Once you've installed the script on your website (you can use the free code snippets plugin to do this), simply identify the third party script with a keyword in the Flying Scripts interface, and it will only be loaded on user interaction.

You can add as many keywords as you want. For example, this is the keyword for the Facebook Messenger live chat that can be installed in any website. “fbevents.js” Refers to the Facebook Pixel and “analytics.js” refers to Google Analytics.

It's really as simple as that.

Perfmatters

Next up is a plugin called Perfmatters. This is a “Jack of all trades” speed optimization tool, but we're going to specifically use the feature that allows you to host Google Analytics scripts locally.

Hosting this script locally allows you to make less DNS requests. This reduces the impact of it on your website's loading time, and resolves the issue “leverage browser caching”.

Enable Google local analytics

All you need to do is toggle local analytics on, and then enter your tracking ID. There are a couple of other features regarding GA that you can ignore or use depending on your website requirements.

For example you can:

  • Disable remarketing and advertising which generates a 2nd HTTP request.
  • Load analytics in the footer of the website which may result in a faster page load and have no impact on view count.

Conclusion

A combination of these two plugins will seriously reduce the impact of 3rd party JavaScript code on your WordPress website. Not only will this result in a higher performance score, but your website will load faster all around resulting in higher ranking placement and a better user experience.

If you have any questions on how to optimize your WordPress website for speed, feel free to reach out in the comment section below.

Join Our Growing Mailing List Of Design Crazed Individuals

Expertly curated emails that will help you generate more income through good design.

You're in the club 💪.

Something went wrong.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
James LePage is the founder of Isotropic Design, a digital agency that builds WordPress websites. I read, write and design constantly!

Social Share

Crafting Stunning Digital Appearances & Assets Out Of New York.
Get In Touch
Syracuse, NY | Charlotte, NC | New York, NY
© 2020 Isotropic, LLC
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram

Join Our Growing Mailing List Of Design Crazed Individuals

Expertly curated emails that will help you generate more income through good design.

You're in the club 💪.

Something went wrong.