Skip to content

Instantly share code, notes, and snippets.

@seanogdev
Last active March 1, 2017 02:46
Show Gist options
  • Select an option

  • Save seanogdev/0f01b307dfe8c7c1c634e39a0bb25547 to your computer and use it in GitHub Desktop.

Select an option

Save seanogdev/0f01b307dfe8c7c1c634e39a0bb25547 to your computer and use it in GitHub Desktop.
Critical CSS in Twig
{% set styleSite = rev("css/style.css") %}
{% if stylesLoaded == true %}
<link rel="stylesheet" href="{{ styleSite }}" />
{% else -%}
<style>{{ craft.inlin.er('/assets/css/critical/' ~ critical ~ '.css') | raw }}</style>
{% include 'includes/scripts/_async-assets' only %}
<script>
var stylesheet = loadCSS('{{ styleSite }}');
onloadCSS( stylesheet, function() {
document.cookie = "css-loaded=1;";
});
</script>
<noscript>
<link rel="stylesheet" href="{{ styleSite }}" />
</noscript>
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment