php - 为 Shopify 延迟 Liquid 中的非关键 CSS
问题描述
我试图通过推迟我的 CSS 和 JS 来提高我的网络性能速度。我是 Shopify/Liquid 的新手,尽管我认为这是一个 PHP 问题,但我不知道。
我的代码是这样的(在 head 标签内):
{{ 'animate.css' | asset_url | stylesheet_tag }}
会变成这样吗?
<!-- Defer animate.css-->
<link rel="preload" href="{{ 'animate.css' | asset_url | stylesheet_tag }}" as="style" onload="this.onload=null;this.rel='stylesheet'">
<noscript><link rel="stylesheet" href="{{ 'animate.css' | asset_url | stylesheet_tag }}"></noscript>
或者我可以像平常在 html 中那样做吗?像这样:
<link rel="preload" href="../assets/animate.css" as="style" onload="this.onload=null;this.rel='stylesheet'">
<noscript><link rel="stylesheet" href="../assets/animate.css"></noscript>
你能帮忙或告诉我这是否正确吗?
解决方案
{{'animate.css' | asset_url }}
是//cdn.shopify.com/s/files/path/to/your/animate.css
{{'animate.css' | asset_url | stylesheet_tag }}
是
<link href="//cdn.shopify.com/s/files/path/to/your/animate.css" rel="stylesheet" type="text/css" media="all">
<link rel="preload" href="{{'animate.css' | asset_url}}" as="style" onload="this.onload=null;this.rel='stylesheet'">
<noscript><link rel="stylesheet" href="{{'animate.css' | asset_url }}"></noscript>
推荐阅读
- javascript - 阻止 div 在桌子上重叠
- oracle-apex - 如何从 Oracle APEX 页面调用 Jira Rest API
- mysql - Mysql 从表中选择顶部项目然后删除并打印
- web - urllib.request 模块发出的请求和浏览器发出的请求一样吗?
- python - Python蜘蛛在文件上写空行时显示数据框的行元素
- python-3.x - 输入功能后如何触发自动输入按键?
- javascript - 我试图刮亚马逊,并停在一个特定的数字
- java - file.xml 有问题
- python - 如何在 Windows [Python] 上安装没有二进制轮子的 numpy
- javascript - JavaScript 函数分别返回 False 和 0