Skip to content

Instantly share code, notes, and snippets.


Konstantin Vyatkin tinovyatkin

View GitHub Profile
tinovyatkin / loadFont.js
Last active Mar 15, 2017
My function to async load web fonts (real WOFF and WOFF2, not base64 behemots), cache them to localStorage and reuse on next visits
View loadFont.js
* This function load font from web, stores it in localStorage and reuses on next page loads
* Different to everything I found on the internet due to following facts
* 1. Checks if the font is installed in the system and spend no time if it is
* 2. Loads actual WOFF or WOFF2 fonts (if supported) and not bit base64 encoded version - so it faster
* 3. Uses fetch API and FontFace API if available - it's cool!
* 4. Return promises and uses jQuery for cases where native promises probably not available
* @param fontName (Field for font-face)
* @param fontUrl (full URL but without .woff nor .woff2 extensions - format will be selected automatically)
You can’t perform that action at this time.