How Do I Use Defer And Lazyload In Base.Css Of Shopify.

How Do I Use Defer And Lazyload In Base.Css Of Shopify.

Step 1: Understanding Defer and Lazy Load

Defer and lazy loading are techniques used to optimize the loading of CSS files in a Shopify theme. Defer loading ensures that the CSS file is loaded after the initial rendering of the page, while lazy loading delays the loading of CSS until it is actually needed. Implementing these techniques can improve your Shopify store’s performance and page load times. 

Step 2: Locate base.css

The first step is to locate the base.css file in your Shopify theme. This CSS file typically contains foundational styles for your store. You can find it by navigating to the theme editor in your Shopify admin dashboard:

    • Go to your Shopify admin dashboard.
    • Click on “Online Store” and then “Themes.”
    • In the “Current theme” section, click “Actions” and select “Edit code.”
  • Look for the base.css file in the “Assets” folder within the theme files.

Step 3: Copy the CSS Code

Open the base.css file and copy its entire CSS code. You’ll need this code to inline it in your theme.liquid file.

Step 4: Edit theme.liquid

In your Shopify theme, you can use the theme.liquid file to include CSS inline using <style> tags. Here’s how to do it:

  • In the theme code editor, locate the theme.liquid file. This file is usually found in the “Layout” or “Sections” folder.
  • Within the <head> section of the theme.liquid file, add the following code:

liquid

Copy code

<style>

/* Paste the copied CSS code from base.css here */

</style>

This code will insert your base.css code directly into the HTML document of your theme, inlining the CSS.

Step 5: Save Changes

After pasting the CSS code into the <style> tags, save your changes in the theme.liquid file.

Step 6: Implement Defer and Lazy Loading

To implement defer and lazy loading, you’ll need to add attributes to the <style> tag in your theme.liquid file.

  • For defer loading, add the defer attribute like this:

liquid

Copy code

<style defer>

/* Paste the copied CSS code from base.css here */

</style>

  • For lazy loading, add the loading=”lazy” attribute like this:

liquid

Copy code

<style loading=”lazy”>

/* Paste the copied CSS code from base.css here */

</style>

These attributes instruct the browser to load the CSS file in a deferred or lazy manner, optimizing page loading.

Step 7: Test Your Changes

After implementing defer and lazy loading for base.css, it’s essential to thoroughly test your Shopify store to ensure that everything functions correctly. Check various pages, product listings, and checkout processes to confirm that the CSS changes have not caused any issues.

In conclusion, inlining base.css in your Shopify theme’s theme.liquid file with defer and lazy load attributes can help optimize your store’s performance. By following these steps, you can enhance page load times and create a smoother shopping experience for your customers.

Reference: Shopify Liquid documentation.

Leave A Comment

X
×

Hello Business Owner
Seeking E-commerce Expertise? Get Free Consultation Now!

× How can I help you?