Friday, August 11, 2023
HomeProgrammingqueryLocalFonts

queryLocalFonts


One of many bigger downloads when requesting a webpage are customized fonts. There are a lot of nice methods for lazy loading fonts to enhance efficiency for these on poor connections. By getting perception into what fonts the consumer has obtainable, we will 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 by way of a browser immediate when first executed. queryLocalFonts returns an array of FontData objects which include details about all obtainable fonts:

const localFonts = await window.queryLocalFonts();

// [FontData, FontData, ...]

/*
{
  household: "Academy Engraved LET",
  fullName: "Academy Engraved LET Plain:1.0",
  postscriptName: "AcademyEngravedLetPlain",
  model: "Plain",
}
*/

If you would like to focus on a particular font face, you may as well 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 an alternative of downloading costly customized fonts. The immediate for permissions looks like it could deter customers from permitting the API, nevertheless. It is so cool that this API exists although!

  • Vibration API

    Lots of the new APIs supplied to us by browser distributors are extra focused towards the cell consumer than the desktop consumer.  A kind of easy APIs the Vibration API.  The Vibration API permits builders to direct the machine, utilizing JavaScript, to vibrate in…

  • Animating CSS3 Transforms with MooTools Fx
  • Fixing sIFR Printing with CSS and MooTools

    Whereas I am not an enormous sIFR advocate I can perceive its attract. A buyer just lately requested us to implement sIFR on their web site however I bumped into an issue: the sIFR headings would not print as a result of they have been Flash objects. Here is the best way to repair…

  • Font Replacement Using Cufón

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments