All Projects → filamentgroup → Woff2 Feature Test

filamentgroup / Woff2 Feature Test

Licence: mit
A simple feature test for the WOFF2 font format

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Woff2 Feature Test

Hack
A typeface designed for source code
Stars: ✭ 14,543 (+13619.81%)
Mutual labels:  font, web-fonts
fonts
Web fonts that you probably won't find in a CDN
Stars: ✭ 26 (-75.47%)
Mutual labels:  font, web-fonts
gatsby-omni-font-loader
Font loader optimized for maximum performance. Removes render-blocking font resources and loads them asynchronusly. Handle FOUT & FOUC with font loading status watcher. Supports both local-hosted fonts and web fonts.
Stars: ✭ 98 (-7.55%)
Mutual labels:  font, web-fonts
Karmilla
An expanded version of the amazing Karla webfont, adding support for various languages (French, German, Norse, Hungarian, Latvian, Icelandic...)
Stars: ✭ 130 (+22.64%)
Mutual labels:  font, web-fonts
Web Font Loading Recipes
A bunch of demos for different web font loading strategies. Companion to https://www.zachleat.com/web/comprehensive-webfonts/ Read more: https://www.zachleat.com/web/recipes/
Stars: ✭ 964 (+809.43%)
Mutual labels:  font, web-fonts
Powerline Web Fonts
Powerline Web Fonts for Chromebook
Stars: ✭ 178 (+67.92%)
Mutual labels:  font, web-fonts
webfont-kit-generator
Create @ font-face kits easily
Stars: ✭ 52 (-50.94%)
Mutual labels:  font, web-fonts
Webfont
Awesome generator of webfont
Stars: ✭ 170 (+60.38%)
Mutual labels:  font, web-fonts
Pokemon Font
GAME BOY font from Pokémon R/G/B/Y/G/S/C, Unicode extended.
Stars: ✭ 437 (+312.26%)
Mutual labels:  font, web-fonts
Fontfaceonload
A simple utility to execute a callback when a webfont loads.
Stars: ✭ 367 (+246.23%)
Mutual labels:  font, web-fonts
glyphhanger
Your web font utility belt. It can subset web fonts. It can find unicode-ranges for you automatically. It makes julienne fries.
Stars: ✭ 422 (+298.11%)
Mutual labels:  font, web-fonts
Faux Pas
A script to highlight elements that are mismatched incorrectly to @​font-face blocks, which may result in shoddy faux bold or faux italic rendering.
Stars: ✭ 93 (-12.26%)
Mutual labels:  font, web-fonts
Brick
Open-source webfont service
Stars: ✭ 2,886 (+2622.64%)
Mutual labels:  font, web-fonts
Webfont Test
Test and analyze fonts for the web: Google fonts, system fonts and custom fonts.
Stars: ✭ 36 (-66.04%)
Mutual labels:  font, web-fonts
Glyphhanger
Your web font utility belt. It can subset web fonts. It can find unicode-ranges for you automatically. It makes julienne fries.
Stars: ✭ 1,099 (+936.79%)
Mutual labels:  font, web-fonts
Cdnjs
🤖 CDN assets - The #1 free and open source CDN built to make life easier for developers.
Stars: ✭ 9,270 (+8645.28%)
Mutual labels:  font
Lab Mono
Grotesque-esque monospaced typeface
Stars: ✭ 99 (-6.6%)
Mutual labels:  font
Source Han Sans
Source Han Sans | 思源黑体 | 思源黑體 | 思源黑體 香港 | 源ノ角ゴシック | 본고딕
Stars: ✭ 10,181 (+9504.72%)
Mutual labels:  font
Official Bash Logo
Everything you need to start using the official GNU Bash logo
Stars: ✭ 89 (-16.04%)
Mutual labels:  font
Sporting Grotesque
A grotesque typeface by @LucasLeBihan
Stars: ✭ 101 (-4.72%)
Mutual labels:  font

woff2-feature-test

A simple feature test for the WOFF2 font format.

Use Case

Given that we use loadCSS to asynchronously load a stylesheet containing all of our typefaces as data URIs, we need a way to programmatically determine if the WOFF2 format is supported in the browser.

var fontFile = "/url/to/woff.css";

// Use WOFF2 if supported
if( supportsWoff2 ) {
	fontFile = "/url/to/woff2.css";
}

loadCSS( fontFile );

Requirements

  1. Must not make an HTTP request to a remote server, anything using a remote test file was out.
  2. Prefer a synchronous approach to an asynchronous one, we want it to execute and the result to be available immediately.
  3. More than just an inference. It was suggested that we could infer based on the existence of the Font Loading API given that it currently matches support for WOFF2. But what happens if a browser implements the Font Loading API but doesn’t implement WOFF2? This scenario seemed entirely possible and we didn’t want any false positives.

Approach

We use the Font Loading API to load an empty WOFF2 data URI and see if the font set status is loading or not. If it attempts to load, the format is supported. If it does not, the format is unrecognized (see the intentionally failing test with an imaginary format).

Demo

If a browser eventually implements the WOFF2 format but does not implement the Font Loading API, this script will report a false negative (which is preferable to the false positive scenarios described above).

Limitations

Note that if you use a restrictive Content Security Policy header on font-src, that can cause issues with this feature test.

You’ll also need to make sure your Content Security Policy allows Data URIs.

For example, github.com (not github.io) uses Content-Security-Policy:default-src *; font-src assets-cdn.github.com; which denies our @font-face Data URI.

Addendum

A few previous revisions of this script can be found on a gist.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].