Home Software Development queryLocalFonts

queryLocalFonts

0
queryLocalFonts
[ad_1]

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 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 data.

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",
  fashion: "Plain",
}
*/

If you would like to focus on a particular font face, you can too straight 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 could deter customers from permitting the API, nevertheless. It is so cool that this API exists although!

  • Facebook Open Graph META Tags

    It is no secret that Fb has turn into a serious site visitors driver for all sorts of internet sites.  These days even giant firms steer customers towards their Fb pages as a substitute of the company web sites straight.  And naturally there are Fb “Like” and “Suggest” widgets on each web site.  One…

  • fetch API

    One of many worst stored secrets and techniques about AJAX on the net is that the underlying API for it, XMLHttpRequest, wasn’t actually made for what we have been utilizing it for.  We have carried out nicely to create elegant APIs round XHR however we all know we will do higher.  Our effort to…

  • Firefox Marketplace Animated Buttons
  • How to Create a Twitter Card

[ad_2]