Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fontfaceobserver

Package Overview
Dependencies
Maintainers
1
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fontfaceobserver

Detect if web fonts are available

  • 2.0.5
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is fontfaceobserver?

FontFaceObserver is a JavaScript library that allows you to monitor the loading of web fonts. It provides a simple and efficient way to ensure that fonts are loaded before they are used, improving the user experience by preventing layout shifts and ensuring text is displayed correctly.

What are fontfaceobserver's main functionalities?

Basic Font Loading

This feature allows you to monitor the loading of a specific font. The code sample demonstrates how to create a new FontFaceObserver instance for the 'Open Sans' font and log a message to the console once the font has loaded or if it fails to load.

const FontFaceObserver = require('fontfaceobserver');

const font = new FontFaceObserver('Open Sans');

font.load().then(function () {
  console.log('Open Sans has loaded');
}).catch(function () {
  console.log('Open Sans failed to load');
});

Loading Fonts with Specific Variants

This feature allows you to monitor the loading of a specific font variant, such as a bold or italic version. The code sample demonstrates how to create a new FontFaceObserver instance for the 'Open Sans' font with a weight of 700 (bold) and log a message to the console once the font has loaded or if it fails to load.

const FontFaceObserver = require('fontfaceobserver');

const font = new FontFaceObserver('Open Sans', {
  weight: 700
});

font.load().then(function () {
  console.log('Open Sans Bold has loaded');
}).catch(function () {
  console.log('Open Sans Bold failed to load');
});

Loading Multiple Fonts

This feature allows you to monitor the loading of multiple fonts simultaneously. The code sample demonstrates how to create FontFaceObserver instances for both 'Open Sans' and 'Roboto' fonts and log a message to the console once both fonts have loaded or if one or more fonts fail to load.

const FontFaceObserver = require('fontfaceobserver');

const openSans = new FontFaceObserver('Open Sans');
const roboto = new FontFaceObserver('Roboto');

Promise.all([openSans.load(), roboto.load()]).then(function () {
  console.log('Open Sans and Roboto have loaded');
}).catch(function () {
  console.log('One or more fonts failed to load');
});

Other packages similar to fontfaceobserver

Keywords

FAQs

Package last updated on 04 Oct 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc