Here’s the Unicode range from Google Web Fundamentals.Īs you can see we use only optimised fonts ( woff and woff2) and we tell the browser to load only the required glyphs range (from U+000 to U+5FF), but this property doesn’t prevent browsers to download the entire font. Here a correct example declaring a custom font family: Correct font-face declarationĭeclaring a font-face family is very simple but we must take care with certain things when we do it. Consider using ?? instead for easier maintenance. Fonts can also be regularly updated, and if you’re preloading an old version while using the CSS for a newer one, you may end up downloading two versions of the same font and wasting your users’ bandwidth. If you’re using a CDN like Google Fonts, be sure that the font files you’re preloading match the ones in the CSS. You can instead use the rel="prefetch" attribute to tell the browser to prepare the download of the resources that may be required later during page load or user actions so it will assign a low priority to those resources. Browsers that support preload and prefetch hints will start downloading web fonts as soon as they have seen the hint in the HTML file and no longer need to wait for the CSS. Using the preload hints will have a dramatic impact on web font performance and initial page load. They also tell the browser that this is a font, so it can appropriately prioritise it in its resource queue. In the above example, the rel="preload" as="font" attributes will ask the browser to start downloading the required resource as soon as possible. This is because fonts are expected to be fetched anonymously by the browser, and the preload request is only made anonymous by using the this attribute. Note that the use of crossorigin here is important without this attribute, the preloaded font is ignored by the browser, and a new fetch takes place. When using custom fonts you should tell the browser to preload them using the appropriate rel="" tag and attributes: These are the only two file types you should use because they are compressed in the gzip format by default (so they are very small), are optimised for the web, and are fully supported by IE 9+ and all other evergreen browsers. There are many font formats that can be used on the web, but only two formats are really needed if you don’t have to support Internet Explorer (IE) 8 or lower: woff and woff2. Let’s break down these points one at a time. Avoid invisible text during font loading. There are just four steps to consider when loading a custom web font: It’s time to break this loop and start doing the right thing in 2019. I see many developers ignoring these issues or perhaps making the same errors over and over just because “they have always done so”, but as web developers we need to be able to adapt in a constantly changing environment. This causes a lot of problems for page loading like performance issues, slow loading time, blocked rendering and swapped fonts during navigation. Custom web fonts are used everywhere around the world, but many (oh so many) sites load them improperly.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |