Skip to content

Commit 3dc9ae8

Browse files
committed
Expand code snippet comment
Some important nuance was missed in the comment. It has nothing to do with Obs.js, but folk may find it interesting.
1 parent b3165b2 commit 3dc9ae8

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

demo/index.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,11 +284,13 @@ <h1>Obs.js: context-aware web performance for everyone</h1>
284284

285285
<script class=c-snippet>
286286
(() => {
287+
287288
// Only load Google Fonts if we can show rich media. In browsers that
288289
// don’t support the relevant APIs, we just go ahead and load it.
289290
//
290291
// Attach it to the end of the `body` rather than the `head` so it doesn’t
291292
// inadvertently block rendering.
293+
292294
if (window.obs?.shouldAvoidRichMedia === true) {
293295
return;
294296
} else {
@@ -297,6 +299,16 @@ <h1>Obs.js: context-aware web performance for everyone</h1>
297299
gf.href = 'https://fonts.googleapis.com/css2?family=Fredoka:wght@300..700&display=swap';
298300
document.body.appendChild(gf);
299301
}
302+
303+
// Fun fact: because this `script` is a classic, inline, synchronous
304+
// `<script>`, ‘the end of the `body`’ in the context of this snippet is
305+
// actually immediately after this text you’re reading right now. Open
306+
// DevTools and you’ll see the Google Fonts stylesheet isn’t actually at
307+
// the `</body>`, but immediately after this code block.
308+
//
309+
// Another fun fact: this text you’re reading right now is the *exact*
310+
// code that the browser just executed. It just has `display: block;`
311+
// applied to it. Neat!
300312
})();
301313
</script>
302314

@@ -339,8 +351,10 @@ <h2><code>&lt;video&gt;</code> Demo</h2>
339351

340352
<script class=c-snippet>
341353
(() => {
354+
342355
// Inject a video if we’re on a good enough connection, otherwise just
343356
// inject a screenshot image.
357+
344358
const videoWrapper = document.getElementById('jsVideo');
345359

346360
if (window.obs?.shouldAvoidRichMedia === true) {

0 commit comments

Comments
 (0)