Improving web font performance with service workers

Improving web font performance with service workers

Over the last few days, we’ve looked at how to self-host web fonts and how to load them asynchronously for better performance. Today, we’re going to look at how to cache them with service workers for even better performance. (If you haven’t yet, you should go read the rest of my service worker series first or this article won’t make a ton of sense.) Adding a web font to your site For today’s lesson, we’re going to use PT Serif, the same typeface I use for my sites, and we’re going to self-host them.

Over the last few days, we’ve looked at how to self-host web fonts and how to load them asynchronously for better performance.

Today, we’re going to look at how to cache them with service workers for even better performance.

(If you haven’t yet, you should go read [the rest of my service worker series_](https://gomakethings.com/series/service-workers/) first or this article won’t make a ton of sense._)

Adding a web font to your site #

For today’s lesson, we’re going to use PT Serif, the same typeface I use for my sites, and we’re going to self-host them.

After downloading them, I’m going to add them to a /fonts directory. Then I’m going to create a fonts.css in my /css directory that loads them.

@font-face {
    font-family: "PT Serif";
    font-style: normal;
    font-weight: 400;
    src: local("PT Serif"), local("PTSerif-Regular"), url("fonts/pt-serif-v11-latin-regular.woff2") format("woff2"), url("fonts/pt-serif-v11-latin-regular.woff") format("woff");
}

/* ... */

Next, inside my main styles for the page, I’m going to use PT Serif as my font-family.

body {
    font-family: "PT Serif", serif;
}

And finally, on each HTML file on my site, I’m going to load my fonts.css file asynchronously.

<link rel="stylesheet" href="css/fonts.css" media="print" onload="this.media='all'; this.onload=null;">

Now I’ve got a custom web font loading on my site, and I’m ready to add service workers to improve the performance.

web

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

whatsapp web-w app web-webs whatsapp »

whatsapp web-w app web-webs whatsapp-web.whatsapp.com-wsp web-web.whatsapp.com qr-whats up online-whatsappwebsite

What's the Link Between Web Automation and Web Proxies?

Web automation and web scraping are quite popular among people out there. That’s mainly because people tend to use web scraping and other similar automation technologies to grab information they want from the internet. The internet can be considered as one of the biggest sources of information. If we can use that wisely, we will be able to scrape lots of important facts. However, it is important for us to use appropriate methodologies to get the most out of web scraping. That’s where proxies come into play.

Mobile Responsive Web Design

Skenix Infotech is a top-rated responsive website design company that provides creative responsive web design services at reasonable prices. Get in touch today!

Important Reasons to Hire a Professional Web Development Company

    You name the business and I will tell you how web development can help you promote your business. If it is a startup or you seeking some...

Why Web Development is Important for your Business

With the rapid development in technology, the old ways to do business have changed completely. A lot more advanced and developed ways are ...