Home » Shopify » Optimization Tricks for Shopify Theme Development

Optimization Tricks for Shopify Theme Development

Introduction

The success of Shopify themes depends on efficient Liquid optimization strategies to achieve optimized pages that are fast and user-friendly online stores. The article examines theme performance improvements through different techniques, including minifying CSS and JavaScript for Shopify and AJAX loading, together with their strengths and weaknesses and offers actual programming examples for developers.

1. Minimizing and Deferring CSS and JavaScript

The performance of pages becomes faster through file size reduction of CSS and JavaScript contents along with delayed loading operations.

Approach:

  • Minification removes all extra code characters that still maintain program operation.
  • Preload: Preload important resource CSS files for optimized pages.
  • Defer JavaScript: The delayed execution of non-essential scripts should occur only after the main page content becomes visible, ensuring optimized page performance.

Pros:

  • Faster initial page load, creating optimized pages.
  • Improved user experience.

Cons:

  • Insightful debugging becomes harder when working with code that has been minified.
  • Complexity in managing script dependencies.

Example:

Defer JavaScript code and preload important CSS for optimized pages.

code-a

2. Lazy Loading Images

The important performance-boosting technique of lazy loading image loading until users require them decreases page load times in both the initial stages and final stages, which helps in achieving optimized pages. Shopify stores heavily benefit from high-quality product images as well as banner images because they directly affect page loading speed.

Hero banners along with featured product images should be kept outside the lazy loading scope since they appear above the fold. A faster Largest Contentful Paint (LCP) occurs due to this method which plays a crucial role in improving Core Web Vitals measurement along with SEO ranking and user satisfaction and helping create optimized pages.

Approach:

  • Each image tag must include the “lazy” loading parameter except the first image above the fold, ensuring optimized pages.

Pros:

  • Decreased initial page load time for optimized pages.
  • Bandwidth conservation.

Cons:

  • The timing of image loading becomes a user experience concern when implemented without proper care.

Implementation in Shopify

First Image (Above the Fold) – Load Normally (No Lazy Loading)

The loading=”lazy” attribute should not be added to images that need to appear urgently after page loading including hero images and main product photos displayed above the fold.

code-b

Other Images (Lazy Loading Applied)

All other images that are below the fold should use lazy loading.

code-c

3. Dynamic Product Loading on Collections

The dynamic loading of products during user scroll acts as a performance-enhancing strategy for Shopify collection pages. This approach helps in serving optimized pages by reducing initial load times.

Approach:

  • A JavaScript and AJAX implementation of infinite scrolling combined with “Load More” buttons provides flexible scrolling abilities to users, improving optimized pages.

Pros:

  • Improved performance on pages with many products, creating optimized pages.
  • Enhanced user engagement.

Cons:

  • Increased complexity in implementation.
  • The improper management of this issue could lead to SEO problems.

Example:

Product loading through AJAX allows users to obtain additional products dynamically.

code-d

4. Serving Appropriately Sized Images

For Shopify theme performance optimization, you must deliver images that match the designated dimensions to achieve optimized pages. Page loading durations increase when large images are used while images that are too small can become blurry on high-resolution screens. Creating image delivery systems that optimize performance by finding adequate image dimensions that match user devices constitutes the main aim.

Approach:

  • Allow browsers to choose optimal images through srcset and size attributes based on screen dimensions and display resolution.
  • The Shopify Image Filters (image_url)  enable automatic serving of correct image sizes because Shopify runs them through Liquid filters for built-in image resizing.
  • Adding WebP images gives you high compression power above JPEG and PNG yet maintains original quality.

Recommended Image Sizes

When developing Shopify themes, it’s important to use properly sized images for different screen resolutions to improve page speed, maintain image quality, and optimize user experience. The formulas below help calculate high-resolution image sizes for different devices, including Retina displays on iPhones and iPads.

Hero Banners / Slideshow Images

Hero banners are the largest visual elements and require high-resolution images for crisp clarity on all devices.

  • Desktop: 1920 × 800 px
  • Mobile (Android & iOS): 1080 × 600 px
  • iPhone Retina Display (2x / 3x Scaling):
    • Formula: Base Width × Scale Factor and Base Height × Scale Factor
    • Calculation for iPhone 14 Pro Max (3x scale, recommended at 1.5x to 2x):
      • Width: 1080 × 1.5 = 1620 px
      • Height: 600 × 1.5 = 900 px
    • Result: 1620 × 900 px (for sharper visuals on Retina screens)

Product Images

Shopify recommends using square product images for uniformity across the store.

  • Desktop: 1000 × 1000 px (or larger for zoom features, up to 2048 × 2048 px)
  • Mobile: 600 × 600 px
  • iPhone Retina Display (2x Scaling for sharper images):
    • Formula: Base Width × 2 and Base Height × 2
    • Calculation:
      • Width: 600 × 1.5 = 900 px
      • Height: 600 × 1.5 = 900 px
    • Result: 900 × 900 px (for iPhones with high pixel density screens)

Featured Blog Images

Blog images need to be social media-friendly while remaining sharp across different devices.

  • Desktop: 1200 × 630 px (Recommended for Facebook & Twitter sharing)
  • Mobile: 600 × 315 px

iPhone Retina Display (1.5x Scale Factor):

  • Calculation:
  • Width: 600 × 1.5 = 900 px
  • Height: 315 × 1.5 = 473 px
  • Result: 900 × 473 px

 

 

Logo Image

  • Recommended: The most suitable size for this image element should be 250×100 pixels but SVG format enables scaling flexibility for the best results.

Pros:

  • Optimized loading for various devices, ensuring optimized pages.
  • Improved visual quality.

Cons:

  • Stores must generate and administer multiple image file dimensions for optimal performance, creating more work but resulting in optimized pages.

Code Implementation

code-e

Ready to launch your Shopify store? We will create a standout site with our development and optimization to build a store that sells.

Contact us now and get your store up and running fast!

5. Leveraging Shopify’s Content Delivery Network (CDN)

Shopify’s Content Delivery Network (CDN) accelerates content delivery by serving assets (images, stylesheets, scripts) from the closest server to the user. This reduces latency and improves page speed.

Incorrect Approach: Hosting Assets Externally or Locally

Loading assets from an external server (instead of Shopify’s CDN) adds extra HTTP requests, increasing load times and reducing optimization benefits.

Example: Wrong Way (Self-Hosting or External Links)

tricks-code-a

Correct Approach: Hosting Assets on Shopify’s CDN

Shopify automatically provides a CDN for theme assets, including images, stylesheets, and JavaScript files.

Example: Right Way to Load Assets from Shopify’s CDN

Use the asset_url or shopify_asset_url Liquid filters to properly reference files stored in Shopify’s CDN.

tricks-code-b

6. Reducing Liquid Code Complexity

Simplifying Liquid code enhances rendering speed and maintainability, resulting in more optimized pages.

Approach:

  • Avoid excessive nesting and loops to improve code efficiency and page speed, resulting in optimized pages.
  • Use caching strategies for repeated content to improve optimized page performance.

Pros:

  • Improved server-side rendering performance for optimized pages.
  • Easier code maintenance.

Cons:

  • May require restructuring existing codebases.

Example:

Caching a complex snippet:

code-f

Recommendations and Best Practices

  • Regular Audits: Utilize tools such as Shopify’s Theme Inspector to identify and address performance issues for optimized pages.
  • Efficient Coding: Write clean, concise Liquid code to enhance readability and performance, leading to optimized pages.
  • Asset Management: Host assets on Shopify’s CDN and ensure they’re optimized for web use to improve optimized pages.
  • User-Centric Design: Prioritize features that offer tangible benefits to users without compromising performance, ensuring optimized pages.

Conclusion

Optimizing Shopify themes with Liquid boosts speed, usability, and performance. Using lazy loading, script deferral, and Shopify’s CDN ensures efficiency. A balanced approach with clean code, regular audits, and testing enhances user experience and conversions.

Leave A Comment