Hi @Valeria_16 ,
Thank you for sharing the template code. Let’s go through the code and identify optimizations to improve the Largest Contentful Paint (LCP) for your slideshow images on Shopify.
Key Points in Your Template
- Image Loading Strategy:
- You are using a liquid
rimg
render tag for images.
lazy
loading is set for desktop images but not for mobile images.
- Image Sizes:
- Images are being served with specific sizes:
'2000x'
for desktop and '800x'
for mobile.
- Image Optimization:
- The
canvas: true
option may impact how images are rendered and possibly affect performance.
- Focal points are used, which is good for responsive image cropping.
- Overlay Implementation:
- Overlays are added conditionally with opacity and color settings.
- Links and Buttons:
- Images and content can be wrapped in clickable links, which adds interactivity but could add to load time.
Recommendations for Optimization
Here are some strategies and improvements you might consider:
- Ensure Proper Lazy Loading for All Images
- Lazy load both desktop and mobile images. In your current setup, mobile images are not lazy-loaded, which could lead to performance issues on mobile devices:
{%
render 'rimg',
img: block_slide_image_mobile,
class: 'slideshow-slide__image slideshow-slide__image--mobile',
size: '800x',
lazy: true, // Change to true
canvas: true,
focal_point: block_slide_image_mobile.presentation.focal_point,
%}
- Optimize Image Resolutions
- Utilize responsive images with varying resolutions to ensure appropriately sized images are served to different devices. Here is an example of how you could optimize this:
{%
render 'rimg',
img: block_slide_image,
class: 'slideshow-slide__image slideshow-slide__image--desktop',
size: '2000x', // Consider changing to a srcset attribute
lazy: true,
canvas: true,
focal_point: block_slide_image.presentation.focal_point,
srcset: '1000w, 1500w, 2000w', // Provide multiple sizes for responsive loading
sizes: '(max-width: 600px) 100vw, (max-width: 1200px) 50vw, 33vw'
%}
- Reduce Render-blocking Resources
- Make sure that styles and scripts for the slideshow are non-blocking. Place your CSS in the
<head>
and ensure that JavaScript is loaded asynchronously or deferred, unless it is required for the initial paint.
- Critical CSS for Above-the-fold Content
- Inline critical CSS directly for above-the-fold content to reduce render delay. Extract necessary CSS for the slideshow that affects initial viewport content and inline it.
- Optimize Overlay Implementation
- Evaluate the necessity of the overlay on the initial viewport. Ensure that it doesn’t load until the images are fully visible if it’s not crucial.
{% if block_overlay_opacity != 0 and block_overlay_color != 'rgba(0,0,0,0)' %}
{% endif %}
- Preload Key Resources
- Preload the largest or critical images to hint the browser to prioritize these resources during the loading process:
- Limit the Use of Canvas for Images
- Consider minimizing the use of canvas for image rendering, especially if it’s not essential. Canvas-based rendering can be more resource-intensive than direct image display. Evaluate the impact on performance and opt for rendering images directly if necessary.
{%
render 'rimg',
img: block_slide_image,
class: 'slideshow-slide__image slideshow-slide__image--desktop',
size: '2000x',
lazy: true,
canvas: false, // Set to false if performance improves
focal_point: block_slide_image.presentation.focal_point,
%}
Remember the following tips:
- Use placeholder and progressive loading:
- Implement placeholders for images to enhance perceived performance. You can display a low-resolution image while the high-resolution one loads.
- Optimize CSS and JavaScript for animation:
- Ensure that any animations or transitions in your slideshow are optimized to use hardware acceleration (e.g., transform and opacity). This will make sure that they are smooth and do not block the initial rendering.
Example code adjustments:
Here’s a quick way to incorporate the above suggestions into your existing code:
{% if block_background_link != blank %}
{% endif %}
{% if block_slide_image != blank %}
{% render 'rimg',
img: block_slide_image,
class: 'slideshow-slide__image slideshow-slide__image--desktop',
size: '2000x',
lazy: true,
canvas: false,
focal_point: block_slide_image.presentation.focal_point,
srcset: '1000w, 1500w, 2000w',
sizes: '(max-width: 600px) 100vw, (max-width: 1200px) 50vw, 33vw'
%}
{% else %}
{{ placeholder | placeholder_svg_tag: 'slideshow-slide__image slideshow-slide__placeholder' }}
{% endif %}
{% if block_slide_image_mobile != blank %}
{% render 'rimg',
img: block_slide_image_mobile,
class: 'slideshow-slide__image slideshow-slide__image--mobile',
size: '800x',
lazy: true, // Changed to true
canvas: false,
focal_point: block_slide_image_mobile.presentation.focal_point,
srcset: '400w, 600w, 800w',
sizes: '(max-width: 600px) 100vw, (max-width: 1200px) 50vw, 33vw'
%}
{% endif %}
{% if block_overlay_opacity != 0 and block_overlay_color != 'rgba(0,0,0,0)' %}
{% endif %}
{% if block_background_link != blank %}
{% endif %}
{% if block_background_link != blank %}
{% endif %}
{% if block_preheading != blank %}
{{ block_preheading | escape }}
{% endif %}
{% if block_slide_title != blank %}
##
{{ block_slide_title | escape }}
{% endif %}
{% if block_subheading != blank %}
{{ block_subheading | escape }}
{% endif %}
{% if block_text != blank %}
{{ block_text }}
{% endif %}
{% if block_background_link != blank %}
{% endif %}
{% if block_button_label != blank %}
{% if block_button_link != blank %}
{{ block_button_label | escape }}
{% else %}
{{ block_button_label | escape }}
{% endif %}
{% endif %}
{% if block_button_label_2 != blank %}
{% if block_button_link_
2 != blank %}
{{ block_button_label_2 | escape }}
{% else %}
{{ block_button_label_2 | escape }}
{% endif %}
{% endif %}
By applying these strategies, you can decrease the LCP and enhance the overall performance and user experience of your Shopify store.
If you need further assistance, feel free to reach out!
I hope this helps! If it does, please like it and mark it as a solution!
Regards,
Sweans