Google Fonts. Every WordPress blogger uses them. It’s an easy — if not the easiest — way to improve your blog’s looks. Pagespeed Insights. We’ve all heard of that too. And we all want to achieve the highest possible score. Both are brought to you by the same entity we’ve come to know, love — and hate: Google. Love, because they gave us these beautiful fonts. Hate, because as soon as we use them, it lowers our score on Pagespeed Insights!
Today I’m showing you how you can achieve the best of both worlds:
- Maintain your high score on Pagespeed Insights by leveraging your browser cache, and
- Keep using your Google Fonts by hosting them locally.
And I promise you, it couldn’t be easier.
Locally Hosting Google Fonts shouldn’t be so Difficult.
I know, the web is flooded with tutorials about the essentials of leveraging your browser cache by hosting Google fonts locally. But to be honest: they’re long and boring.
They all explain which files to download, how to upload them to your WordPress blog, how to create a stylesheet, how to add your Google Fonts to said stylesheet, how to enqueue the stylesheet into your WordPress blog, and how to — well, I don’t know. A lot!
When I recently redesigned my blog (well, not really. I used a theme) I lost all my optimizations and my score on Pagespeed Insights plummeted. In other words, I came back around to this tiresome job and I was like:
I’m a backend developer. I don’t want to spend my time creating a stylesheet — no offense. I’d rather spend two days automating a tiresome — booooring — process, than spending one minute exercising said process.
And so I did. You’re welcome.
Host Google Fonts Locally in WordPress using CAOS for Webfonts
POW! There it is! Because of my frustration and arrogance, you now have a powerful WordPress plugin at your disposal. And it’s called CAOS for Webfonts. Not CAOS for Analytics. No. CAOS is my brand now. Consider this his beautiful baby sister. Her name is CAOS for Webfonts.
Because of her, you don’t have to download anything. You don’t have to unpack anything. You don’t have to upload anything. And you don’t have to create anything — especially a frickin’ stylesheet. No offense.
All you have to do is install the plugin from the WordPress repository, select your fonts, and click a button. Let’s do this.
Installing the Plugin from the WordPress Repository
I assume you’ve done this before. I’ll just leave it here for full disclosure:
- From within your WordPress admin-area, go to Plugins > Add new.
- Enter ‘CAOS’ (without the quotes) in the search bar.
- Choose the pink one and click ‘Install now’. Once it’s done, click ‘Activate’.
Configure CAOS for Webfonts
Although the WordPress plugin works fairly straight forward. I thought it might be a good idea to give you a quick crash course. Pay attention.
In theory, you could use this plugin to change your blog’s fonts to anything you like, but we will not be covering that in this tutorial as we’ll have to touch a stylesheet. And if you’ve been paying attention, you’d know that I don’t like stylesheets — no offense.
Most users will want to replace the fonts they’re already using with locally hosted ones. Here’s how you do this:
- Go to Settings > Optimize Webfonts.
- Enter your font’s name in the search bar — you can add as many different fonts as you like!
- Trim the list to include only the fonts your theme actually uses. I usually remove all the ‘italic’ ones, because any modern browser can fake italic fonts.
- Click ‘Generate stylesheet’.
See how easy that was? No 12-step program here! Your fonts have been downloaded and saved on your server, the stylesheet has been generated and added to your theme’s header.
Removing externally hosted Fonts
Now the only thing left to do is remove any mention of externally hosted Google Fonts from your Blog.
I use an integrated option in Autoptimize for this, because I’m already using that plugin for minifcation of my CSS and JS and I suggest you do too — because it’s lightweight and awesome. But if you (are lame and) don’t (want to) use Autoptimize, there’s plenty of other ways to achieve this. Either manually, or through plugins.
Most themes offer an integrated toggle for this in the Theme’s options. If your theme doesn’t, there are many other ways to achieve this.
Why should I host Google Fonts locally?
Locally hosting your Google Fonts gives a great increase in page load times, because your visitor’s browser doesn’t have to make a round-trip to Google’s server to retrieve the files. It also gives you full control of the files’ expiry time, eliminating the Leverage Browser Caching notice on sites offering performance metrics, such as GTMetrix, Pagespeed Insights and Pingdom.