Skip to content

Instantly share code, notes, and snippets.

@eeeps
Last active June 2, 2017 16:58
Show Gist options
  • Save eeeps/c89b9ef28928f2eb5e7db5294be70666 to your computer and use it in GitHub Desktop.
Save eeeps/c89b9ef28928f2eb5e7db5294be70666 to your computer and use it in GitHub Desktop.
Can we initialize a ResizeObserver in the head, and start observing elements as they are parsed on first load with a MutationObserver?
<!doctype html>
<head>
<title>FoUC-free container queries</title>
<script>
const ro = new ResizeObserver( ( entries) => {
// do container query stuff
} );
const mo = new MutationObserver( ( mutations ) => {
// `ro.observe( relevantElement )`s as they are parsed and added to the DOM
} );
mo.observe( document, { childList: true, subtree: true } );
</script>
</head>
<body>
<p>Cool</p>
<p>refreshing</p>
<p>content</p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment