Skip to content

Commit

Permalink
Merge pull request #316 from Modularfield/main
Browse files Browse the repository at this point in the history
Optimize Image Loading with Responsive Sizes Attribute in ProductCard Component
  • Loading branch information
thomasKn authored Sep 16, 2024
2 parents 763a4c8 + 947ed8e commit 21ac09f
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions app/components/product/ProductCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,25 @@ export function ProductCard(props: {
? flattenConnection(product?.variants)
: null;
const firstVariant = variants?.[0];
const sizes = cx([
const sizes = [
'(min-width: 1024px)',
columns?.desktop ? `${100 / columns.desktop}vw,` : '33vw,',
columns?.mobile ? `${100 / columns.mobile}vw` : '100vw',
]);
columns?.desktop ? `${100 / columns.desktop}vw` : '33vw',
columns?.mobile ? `${100 / columns.mobile}vw` : '100vw'
].join(', ');

/**
* Optional: Extended more granular image sizes
*
const sizes = [
'(min-width: 1200px) and (max-width: 1599px)',
columns?.desktop ? `${100 / columns.desktop}vw` : '25vw',
'(min-width: 1024px) and (max-width: 1199px)',
columns?.desktop ? `${100 / columns.desktop}vw` : '33vw',
'(min-width: 768px) and (max-width: 1023px)',
columns?.mobile ? `${100 / columns.mobile}vw` : '50vw',
'100vw'
].join(', ');
*/

const path = useLocalePath({path: `/products/${product?.handle}`});

Expand Down

0 comments on commit 21ac09f

Please sign in to comment.