Detecting Fonts Ready
Knowing when resources are loaded is a key part of building functional, elegant websites. We're used to using the DOMContentLoaded
event (commonly referred to as "domready") but did you know there's an event that tells you when all fonts have loaded? Let's learn how to use document.fonts
!
The document.fonts
object features a ready
property which is a Promise representing if fonts have been loaded:
// Await all fonts being loaded
await document.fonts.ready;
// Now do something! Maybe add a class to the body
document.body.classList.add('fonts-loaded');
Font files can be relatively large so you can never assume they've loaded quickly. One simply await
from document.fonts.ready
gives you the answer!
If you follow me on Twitter, you know that I've been working on a super top secret mobile application using Appcelerator Titanium. The experience has been great: using JavaScript to create easy to write, easy to test, native mobile apps has been fun. My...
The HTML5 revolution has provided us some awesome JavaScript and HTML APIs. Some are APIs we knew we've needed for years, others are cutting edge mobile and desktop helpers. Regardless of API strength or purpose, anything to help us better do our job is a...
The Dojo Toolkit is a treasure chest of great JavaScript classes. You can find basic JavaScript functionality classes for AJAX, node manipulation, animations, and the like within Dojo. You can find elegant, functional UI widgets like DropDown Menus, tabbed interfaces, and form element replacements within...