-
-
Save jssee/8e69057cb12cf033c1e13369fb5af0e6 to your computer and use it in GitHub Desktop.
CSS delivery optimization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="en"> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="initial-scale=1, width=device-width"> | |
<title>Defer non-essential stylesheets</title> | |
<style> | |
/* Critical above-the-fold styles */ | |
* { margin: 0; padding: 0 } | |
:root { background: red } | |
header { color: blue } | |
</style> | |
<main> … </main> | |
<script> | |
// Secondary stylesheets | |
const stylesheets = ["main", "footer"]; | |
requestAnimationFrame(() => | |
document.head.insertAdjacentHTML("beforeend", | |
stylesheets.reduce((a, b) => `${a}<link rel=stylesheet href=${b}.css>`, ""))); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment