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

By Cronos Editorial Staff on May 02, 2022
Est. Reading: 4 minutes
Contents

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 the 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 the third party, PageSpeed will tell you that reducing the impact of its loading on your website will speed up your time and improve your score. Additional third-party scripts that impact your website’s 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 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 non-critical 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 (fewer 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 deferring because (noncritical) scripts simply are not loaded unless a user interacts with the page.

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

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 fewer DNS requests. This reduces its impact of it on your website’s loading time, and resolves the issue of “leverage browser caching”.

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.

Read More: Thrive Architect Review (2022) – is it worth it?

Elementor Review – How Good Is It In 2022?

How To Increase The WordPress Upload Limit On An AWS Lightsail Bitnami Installation

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *