Saturday, August 12, 2023

queryLocalFonts


One of many bigger downloads when requesting a webpage are customized fonts. There are numerous 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 are able to keep away from loading customized fonts. That is the place queryLocalFonts is available in — an native JavaScript perform to assemble 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 comprise 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, you may as well instantly question the postscriptName property:

const canelaFonts = await window.queryLocalFonts({
  postscriptNames: ["Canela", "Canela-Bold"],
});

// [FontData, FontData, ...]

With queryLocalFonts you’ll be able to leverage a fonts a consumer already has as an alternative of downloading costly customized fonts. The immediate for permissions looks like it might deter customers from permitting the API, nevertheless. It is so cool that this API exists although!

  • Being a Dev Dad

    I get requested a great deal of questions daily however I am all the time stunned that they are hardly ever questions on code and even tech — most of the questions I get are extra about non-dev stuff like what my workplace is like, what software program I take advantage of, and oftentimes…

  • Responsive Images: The Ultimate Guide

    Likelihood is that any Internet designers utilizing our Ghostlab browser testing app, which permits seamless testing throughout all units concurrently, may have labored with responsive design in some form or type. And as at this time’s web sites and units grow to be ever extra diversified, a plethora of responsive pictures…

  • MooTools OpenLinks Class – Updated
  • Assign Anchor IDs Using MooTools 1.2

    Certainly one of my favourite makes use of of the MooTools JavaScript library is the SmoothScroll plugin. I apply it to my web site, my employer’s web site, and on many buyer web sites. The very best half in regards to the plugin is that it is really easy to implement. I not too long ago ran…



Supply hyperlink
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments