Skip to content

Commit 1262374

Browse files
author
Prinzhorn
committed
added documentation for using Web Font Loader as CommonJS module
1 parent a1d50eb commit 1262374

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ It is also possible to use the Web Font Loader asynchronously. For example, to l
4444
WebFontConfig = {
4545
typekit: { id: 'xxxxxx' }
4646
};
47-
47+
4848
(function(d) {
4949
var wf = d.createElement('script'), s = d.scripts[0];
5050
wf.src = 'https://ajax.googleapis.com/ajax/libs/webfont/1.5.18/webfont.js';
@@ -57,6 +57,18 @@ Using the Web Font Loader asynchronously avoids blocking your page while loading
5757

5858
The FOUT can be more easily avoided when loading the Web Font Loader synchronously, as it will automatically set the `wf-loading` class on the HTML element as soon as `Webfont.load` has been called. The browser will wait for the script to load before continuing to load the rest of the content, FOUT is avoided.
5959

60+
Web Font Loader is also available on npm as a CommonJS module. Just `npm install webfontloader` and then require it in your code.
61+
62+
```js
63+
var WebFont = require('webfontloader');
64+
65+
WebFont.load({
66+
google: {
67+
families: ['Droid Sans', 'Droid Serif']
68+
}
69+
});
70+
```
71+
6072
## Configuration
6173

6274
The Web Font Loader configuration is defined by a global variable named `WebFontConfig`, or passed directly to the `WebFont.load` method. It defines which fonts to load from each web font provider and gives you the option to specify callbacks for certain events. When using the asynchronous approach, you must define the global variable `WebFontConfig` before the code that loads the Web Font Loader (as in the example above).

0 commit comments

Comments
 (0)