Skip to content

Instantly share code, notes, and snippets.

@jlengstorf
Created June 23, 2018 00:34
Show Gist options
  • Save jlengstorf/4b39f2e5442620f1d26c14d48b580684 to your computer and use it in GitHub Desktop.
Save jlengstorf/4b39f2e5442620f1d26c14d48b580684 to your computer and use it in GitHub Desktop.
Load third-party CSS in a non-blocking way.
<html>
<head>
<!-- head content -->
</head>
<body>
<!-- body content -->
<script type="text/javascript">
(function() {
// TODO replace this with the third-party CSS to load.
const path = 'https://example.org/styles.css';
// Create a link element that loads our third-party CSS.
const link = document.createElement('link');
link.setAttribute('rel', 'stylesheet');
link.setAttribute('type', 'text/css');
link.setAttribute('href', path);
// Add the new link to the <head>.
document.querySelector('head').appendChild(link);
})();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment