Optimize Fonts - Remove Async Google Fonts (Pro)

Since v3.6.0 OMGF Pro sports a feature, called Remove Async Google Fonts.

As you might guess, this feature allows you to remove (or technically speaking; block) Google Fonts from your website, which are loaded asynchronously.

When this option is enabled, OMGF Pro loads a tiny snippet of code (<1KB) into your site's header, which makes sure no requests are made to the Google Fonts API (https://fonts.googleapis.com/css). During my testing, I found themes like Enfold and Customizr to load Google Fonts asynchronously.

For reasons mentioned here, this doesn't work when the request is made from within an iframe, e.g. embedded Google Maps, a tawk.to support chat widget, YouTube video, etc.

Use Case

Blocking Asynchronous Requests

If you want to make sure no asynchronous requests to Google Fonts are made, e.g. by a plugin, then all you need to do is enable this option.

In my testing environment, running Enfold, Google Fonts are loaded asynchronously using a appendChild() method, Remove Async Google Fonts fixes this automatically:

Before After
Before After

Replacing Asynchronous Requests with Locally Hosted Files

Besides just blocking the asynchronous request, it's likely you'd like to still use the Google Fonts, but serve them from your server (to comply with GDPR.

I decided to not automate this process, since it's not feasible. JavaScript can be written in many ways, to achieve the same thing, and it's very unlikely I'd be able to build a code parser that'd understand all these different approaches. However, the steps to achieve this are novice level.

First, along with enabling Remove Async Google Fonts, make sure you scroll to the bottom of the Optimize Fonts settings page, and enable Test Mode. This will make sure any changes and optimizations you make with OMGF are only visible to you.

With Test Mode active, the async Google Fonts are visible to your visitors. But they're not visible to you, because they're blocked

Now, visit your site's homepage. Open up your browser's Developer Tools by pressing F12 and navigate to the Console tab. Refresh the page.

For every request to the Google Fonts API blocked by OMGF Pro, it will show a notice in the console, which looks like this:

Keep the tab open and head over to your server's file system.

Head into your theme's directory, preferably a child theme, e.g. /public/wp-content/themes/enfold-child/. Open the functions.php file and add the following code:

	function daan_dev_enqueue_google_fonts()
		wp_enqueue_style('daan-dev-google-fonts', 'YOUR_GOOGLE_FONTS_URL');

	add_action('wp_enqueue_scripts', 'daan_dev_enqueue_google_fonts');

Replace YOUR_GOOGLE_FONTS_URL with the URL(s) mentioned in your console. Make sure that the apostrophes ('') need to stay around the URL.

If you're not comfortable editing PHP files, try the Additional Fonts plugin and install the Google Fonts you found earlier from a user-friendly interface.

OMGF Pro will pick up the Google Fonts URL you inserted using the code snippet above, and make sure they're served from your server and no requests are made to Google's Servers. On top of that you'll be able to fully manage the fonts from OMGF's Manage Optimized Fonts section.

Shopping Cart
  • Your cart is empty.