queryLocalFonts


One of many bigger downloads when requesting a webpage are customized fonts. There are numerous nice methods for lazy loading fonts to enhance efficiency for these on poor connections. By getting perception into what fonts the person has accessible, we will keep away from loading customized fonts. That is the place queryLocalFonts is available in — an native JavaScript operate to collect person font info.

queryLocalFonts is an async operate that requires person 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",
  fashion: "Plain",
}
*/

If you would like to focus on a selected font face, you too can straight 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 person already has as an alternative of downloading costly customized fonts. The immediate for permissions looks as if it will deter customers from permitting the API, nevertheless. It is so cool that this API exists although!

  • 5 Ways that CSS and JavaScript Interact That You May Not Know About
  • Create Spinning Rays with CSS3: Revisited
  • Create Spinning, Fading Icons with CSS3 and MooTools

    A aim of my newest weblog redesign was to follow what I preached a bit extra;  add a bit extra delicate aptitude.  One of many methods I achieved that was through the use of CSS3 animations to alter the show of my profile icons (RSS, GitHub, and so forth.)  I…

  • CSS Animations Between Media Queries

    CSS animations are proper up there with sliced bread. CSS animations are environment friendly as a result of they are often {hardware} accelerated, they require no JavaScript overhead, and they’re composed of little or no CSS code. Very often we add CSS transforms to components through CSS throughout…