You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -56,6 +47,9 @@ Add the following snippet to `gatsby-config.js` plugins array.
56
47
/* Plugin options */
57
48
options: {
58
49
50
+
/* Font loading mode */
51
+
mode:"async",
52
+
59
53
/* Enable font loading listener to handle FOUT */
60
54
enableListener:true,
61
55
@@ -101,24 +95,24 @@ Add the following snippet to `gatsby-config.js` plugins array.
101
95
</tr>
102
96
</thead>
103
97
<tbody>
98
+
<tr>
99
+
</tr>
100
+
<td>mode</td>
101
+
<td>Can be set to `"async"` (default) or `"render-blocking"`. In `async` mode, fonts are loaded in optimal way, but FOUT is visible. In `render-blocking` mode FOUT will happen in rare cases, but the font files will become render-blocking.</td>
102
+
<td>async</td>
104
103
<tr>
105
104
<td>enableListener</td>
106
-
<td>Enable font loading listener to handle Flash Of Unstyled Text. If enabled, CSS classes will be applied to HTML once each font has finished loading.</td>
105
+
<td>Works in `async` mode. Enable font loading listener to handle Flash Of Unstyled Text. If enabled, CSS classes will be applied to HTML once each font has finished loading.</td>
107
106
<td>false</td>
108
107
</tr>
109
-
<tr>
110
-
<td>preconnect</td>
111
-
<td>URLs used for preconnect meta. Base URL where <strong>font files</strong> are hosted.</td>
112
-
<td>[]</td>
113
-
</tr>
114
108
<tr>
115
109
<td>interval</td>
116
-
<td>Font listener interval (in ms). Default is 300ms. Recommended: >=300ms. </td>
110
+
<td>Works if `enableListener` is `true`. Font listener interval (in ms). Default is 300ms. Recommended: >=300ms. </td>
117
111
<td>300</td>
118
112
</tr>
119
113
<tr>
120
114
<td>timeout</td>
121
-
<td>Font listener timeout value (in ms). Default is 30s (30000ms). Listener will no longer check for loaded fonts after timeout, fonts will still be loaded and displayed, but without handling FOUT.</td>
115
+
<td>Works if `enableListener` is `true`. Font listener timeout value (in ms). Default is 30s (30000ms). Listener will no longer check for loaded fonts after timeout, fonts will still be loaded and displayed, but without handling FOUT.</td>
122
116
<td>30000</td>
123
117
</tr>
124
118
<tr>
@@ -131,9 +125,36 @@ Add the following snippet to `gatsby-config.js` plugins array.
131
125
<td>Web fonts config. File link should point to font CSS file. Array of <code>{name: "Font name", file: "https://url-to-font-css.path"}</code> objects.</td>
132
126
<td>[]</td>
133
127
</tr>
128
+
<tr>
129
+
<td>preconnect</td>
130
+
<td>URLs used for preconnect meta. Base URL where <strong>font files</strong> are hosted.</td>
131
+
<td>[]</td>
132
+
</tr>
133
+
<tr>
134
+
<td>preload</td>
135
+
<td>Additional URLs used for preload meta. Preload for URLs provided under `file` attribute of `custom` and `web` fonts are automatically generated.</td>
136
+
<td>[]</td>
137
+
</tr>
134
138
<tbody>
135
139
</table>
136
140
141
+
## Async mode vs Render-blocking mode
142
+
### Async mode
143
+
Load font stylesheets and files in low-priority mode. If you want to add fonts in a performant way, handle FOUT on your own and make sure that the page render times are low, you should use `async` mode.
144
+
145
+
__Pros:__ Performance, content is displayed before font files are downloaded and parsed
146
+
<br/>
147
+
__Cons:__ FOUT needs to be handled
148
+
149
+
### Render-blocking mode
150
+
Load font stylesheets and files in high-priority mode. If you want to use this plugin as a simple way to add fonts to your project as you would do in any other project, without any performance optimizations and FOUT handling, you should use `render-blocking` mode.
151
+
152
+
__Pros:__ Simple markup, FOUT won't occur in most cases
153
+
<br/>
154
+
__Cons:__ Font stylesheets and font files can delay first content paint time
155
+
156
+
157
+
137
158
## Handling FOUT with Font loading listener
138
159
139
160
When loading fonts asynchronously, Flash Of Unstyled Text (FOUT) might happen because fonts load few moments later after page is displayed to the user.
0 commit comments