Skip to content

Instantly share code, notes, and snippets.

@diboune
Created October 1, 2023 11:24
Show Gist options
  • Save diboune/bd3180f36e5b9e963e0338627ad4f2f4 to your computer and use it in GitHub Desktop.
Save diboune/bd3180f36e5b9e963e0338627ad4f2f4 to your computer and use it in GitHub Desktop.
{% comment %}
Lazily importing css stylesheets, without blocking the document download.
Accepts:
- sheets: `string` of the css files seperated by `,`.
Usage:
{% render 'stylesheet-import', sheets: 'component.css,not-component.css' %}
{% endcomment %}
{% assign sheets = sheets | split: ',' %}
{% for sheet in sheets %}
<link rel="stylesheet" href="{{ sheet | asset_url }}" media="print" onload="this.media='all'">
<noscript>{{ sheet | asset_url | stylesheet_tag }}</noscript>
{% endfor %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment