Why does my preloaded product image have a different version?

Why does my preloaded product image have a different version?

Kalipsso
Visitor
2 0 0

Hi there.

I am preloading the product tag for speed improvement and I am using <picture> tag to load the product images.

The problem i have is that the preloaded image has a different version than the product image on the page:

preloaded image: _508x508.jpg?v=1612807210

image on the page: _508x508.jpg?v=1612807211

The code i am using for preloading is this:

<link rel="preload" as="image" href="{{ product.featured_image.src | img_url:'400x400' }}" media="(max-width: 767.98px)">

And the code inside product.liquid is this:

<picture>
<source media="(max-width: 767.98px)" srcset="{{ product.featured_image.src | img_url:'400x400' }}">
<img src="(min-width: 300px)" srcset="{{ product.featured_image.src | img_url:'400x400' }}"
alt="{{ image.alt | escape }}">
</picture>

 Can anyone explain why this happens?

Reply 1 (1)

oscprofessional
Shopify Partner
16366 2440 3188

Hello @Kalipsso ,

The issue you are experiencing with the preloaded image having a different version than the product image on the page is likely due to caching mechanisms and how URLs are handled for image resources. When you preload an image using the <link rel="preload"> tag, the browser fetches and caches that resource based on the URL provided. If the URL includes a query parameter like v=1612807210, it is treated as a unique resource separate from v=1612807211, even if the image content is the same. In your case, the discrepancy in versions (v=1612807210 vs v=1612807211) could be due to how the URLs are generated or managed in your system. It's important to ensure that the URLs for preloaded images and on-page images are consistent to avoid unnecessary re-fetching and caching of the same resource. To address this issue, you can consider the following steps:
  1. URL Consistency: Ensure that the URLs for preloaded images and on-page images are generated consistently, without changing query parameters for the same image version.
  2. Cache Control: Implement proper cache control headers to manage how browsers cache and serve images, ensuring that the correct versions are used.
  3. Versioning Strategy: Consider using a versioning strategy that updates the query parameter only when the image content changes, rather than on every request.
By addressing these points, you can help ensure that preloaded images and on-page images are synchronized, improving performance and avoiding unnecessary resource fetching.
Hire us | Pass Core Web Vital | B2B Wholesale Experts | Claim Your Free Website Review |
Connect with Us: WhatsApp | Skype: oscprofessionals-87 | Email: pallavi@oscprofessionals.com |
Custom Shopify SolutionsPrivate Apps, Theme Customization & SEO | Digital Marketing |
OSCP Apps: Discount Suite | Wholesale App | Bundle & Upsell | Shipping Discount | and more...