Preload Tag
Use preload_tag to generate an HTML <link rel="preload"> tag for a resource. Give the resource type in the as option: style, script, image, font or fetch. The default is style.
With as: 'style' and no other option, you also get a <noscript> fallback. The stylesheet is applied when it is loaded.
With other options, each option is added to the tag as an attribute. An option set to true is added without a value. An option set to false or nil is left out.
liquid
{{ url | preload_tag: options }}Example
liquid
{{ 'https://cdn.example.com/fonts.css' | preload_tag }}Output
html
<link rel="preload" href="https://cdn.example.com/fonts.css" as="style" onload="this.onload=null;this.rel='stylesheet'">
<noscript>
<link rel="stylesheet" href="https://cdn.example.com/fonts.css">
</noscript>liquid
{{ settings.body_font | font_url | preload_tag: as: 'font', type: 'font/woff2', crossorigin: true }}Output
html
<link rel="preload" href="https://fonts.gstatic.com/s/inter/v20/inter.woff2" as="font" type="font/woff2" crossorigin>