Skip to content

Commit 8eca1ae

Browse files
committed
Use Fredoka font if Obs.js allows it
What a neat little demo! Fredoka suits the custom Gotham font used in the logo, but we only load it when conditions allow. I like it.
1 parent 5745430 commit 8eca1ae

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

demo/index.html

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555
h1, h2 {
5656
text-wrap: balance;
5757
color: var(--brand);
58+
font-family: 'Fredoka', system-ui, sans-serif;
59+
font-weight: 500;
5860
}
5961

6062
h1 {
@@ -202,6 +204,12 @@ <h1>Obs.js – context-aware web performance for everyone</h1>
202204
lower-resolution media, forgo web fonts, disable auto-playing video… you name
203205
it.</p>
204206

207+
<p><small>In fact, if you have critically low battery, data saver mode
208+
enabled, or a weak connection, you won’t see the nice rounded
209+
<a href="https://fonts.google.com/specimen/Fredoka"><cite>Fredoka</cite></a>
210+
in the <code>&lt;h1&gt;</code> above—you’ll just see your
211+
<code>system-ui</code> font.</small></p>
212+
205213
<p>It is built and maintained by <a href=https://csswizardry.com>Harry
206214
Roberts</a> under the MIT license.</p>
207215

@@ -223,6 +231,24 @@ <h2><code>window.obs</code></h2>
223231
<p><small><strong>Note:</strong> API support varies by browser; Chromium has
224232
the broadest coverage.</small></p>
225233

234+
<script>
235+
(() => {
236+
// Only load Google Fonts if we can show rich media. In browsers that
237+
// don’t support the relevant APIs, we just go ahead and show it.
238+
//
239+
// Attach it to the end of the `body` rather than the `head` so it doesn’t
240+
// inadvertently block rendering.
241+
if (window.obs?.shouldAvoidRichMedia === true) {
242+
return;
243+
} else {
244+
const gf = document.createElement('link');
245+
gf.rel = 'stylesheet';
246+
gf.href = 'https://fonts.googleapis.com/css2?family=Fredoka:wght@300..700&display=swap';
247+
document.body.appendChild(gf);
248+
}
249+
})();
250+
</script>
251+
226252
<script>
227253
// Render helpers
228254
const byId = id => document.getElementById(id);

0 commit comments

Comments
 (0)