One of many bigger downloads when requesting a webpage are customized fonts. There are a lot of nice strategies for lazy loading fonts to enhance efficiency for these on poor connections. By getting perception into what fonts the consumer has accessible, we will keep away from loading customized fonts. That is the place queryLocalFonts
is available in — an native JavaScript perform to collect consumer font info.
queryLocalFonts
is an async
perform that requires consumer permission through a browser immediate when first executed. queryLocalFonts
returns an array of FontData
objects which include details about all accessible fonts:
const localFonts = await window.queryLocalFonts(); // [FontData, FontData, ...] /* { household: "Academy Engraved LET", fullName: "Academy Engraved LET Plain:1.0", postscriptName: "AcademyEngravedLetPlain", type: "Plain", } */
If you would like to focus on a selected font face, it’s also possible to immediately question the postscriptName
property:
const canelaFonts = await window.queryLocalFonts({ postscriptNames: ["Canela", "Canela-Bold"], }); // [FontData, FontData, ...]
With queryLocalFonts
you possibly can leverage a fonts a consumer already has as a substitute of downloading costly customized fonts. The immediate for permissions looks as if it might deter customers from permitting the API, nonetheless. It is so cool that this API exists although!
39 Shirts – Leaving Mozilla
In 2001 I had simply graduated from a small city highschool and headed off to a small city faculty. I discovered myself within the quaint pc lab the place the substandard computer systems featured two browsers: Web Explorer and Mozilla. It was this lab the place I fell…
5 HTML5 APIs You Didn’t Know Existed
Once you say or learn “HTML5”, you half anticipate unique dancers and unicorns to stroll into the room to the tune of “I am Attractive and I Know It.” Are you able to blame us although? We watched the elemental APIs stagnate for thus lengthy {that a} primary characteristic…
CSS @helps
Function detection through JavaScript is a shopper aspect finest follow and for all the suitable causes, however sadly that very same performance hasn’t been accessible inside CSS. What we find yourself doing is repeating the identical properties a number of instances with every browser prefix. Yuck. One other factor we…
Chris Coyier’s Favourite CodePen Demos IV
Do you know you possibly can triple-heart issues on CodePen? We’ve had that little not-so-hidden characteristic perpetually. You’ll be able to click on that little coronary heart button on any Pen (or Undertaking, Assortment, or Submit) on CodePen to point out the creator somewhat love, however you possibly can click on it once more…
Source link