简体   繁体   English

如何在Liquid中异步或延迟JS?

[英]How to async or defer JS in Liquid?

I'm trying to improve site speed, and one thing that might be delaying render are these scripts: 我正在尝试提高网站速度,这些脚本可能会延迟渲染的一件事:

  {{ '//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js' | script_tag }}
  {{ 'jGestures.min.js' | asset_url | script_tag }}
  {{ 'modernizr.min.js' | asset_url | script_tag }}

How can they be made to asych or defer? 如何使他们避难或延期? Or should I simply move them to the bottom? 还是我应该简单地将它们移到底部? Also I have not made changes like this to my theme yet. 另外,我尚未对主题进行此类更改。 Is it easy to revert changes in Shopify? 在Shopify中还原更改是否容易? I would just change it to the way it was before if any of the scripts were needed for the initial render, correct? 如果将任何脚本用于初始渲染,我将其更改为以前的方式,对吗?

Edit: those scripts are in the HEAD section. 编辑:这些脚本在HEAD部分中。

You have to do it little differently. 您必须做一些不同的事情。

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js" async></script>

<script src="{{ 'jGestures.min.js' | asset_url }}" async></script>

Make sure you copy/download the theme so that you have a backup. 确保复制/下载主题,以便进行备份。 also shopify stores revisions so that you can revert back. 还可以Shopify存储修订,以便您可以还原。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM