CDN and Images
Catalyst renders BigCommerce images through the BigCommerce CDN instead of your host’s image optimization, which avoids image transformation costs on your hosting provider. This page explains how the Catalyst <Image /> component works and how to build CDN URLs for catalog images, WebDAV assets, and Image Manager images.
Images in Next.js
Next.js includes an Image component that provides automatic optimization for rendering images. This component includes features like automatic generation of a srcset for responsive images, as well as lazy loading behavior.
Images rendered with this component are proxied through your own Next.js application, which transforms them. Depending on your hosting provider, you may pay for those image transformations.
The Catalyst Image component
For loading images from the BigCommerce platform, Catalyst provides <Image /> as a wrapper for Next’s <Image /> component to allow you to use BigCommerce CDN URLs directly.
The BigCommerce CDN already transforms images, so this component skips the Next.js transformation step. That reduces load on your application and removes the related hosting costs, with the same syntax as the Next.js component. For images that don’t come from the BigCommerce CDN, it falls back to the default Next.js image loader.
Import it from ~/components/image:
GraphQL-sourced image URLs
By default, <Image /> is used to render many images from BigCommerce data loaded via the GraphQL Storefront API.
These image URLs, such as one queried from a product’s defaultImage field, are BigCommerce CDN URLs, so <Image /> loads them directly:
See Best practices for more about urlTemplate and sizes.
Use store assets uploaded with WebDAV
Two helper functions in lib/store-assets build URLs for assets in your store’s WebDAV storage.
contentAssetUrl() builds a URL to any file in the /content/ folder in your store’s WebDAV storage. This link points to a PDF:
For images uploaded to /content, contentImageUrl() builds a resizable image URL to use with <Image />:
To request a specific size, pass a size parameter of the form 123w, 123x123, or original:
Use images uploaded to Image Manager
imageManagerImageUrl() builds a CDN URL for an image uploaded to Image Manager. It returns a resizable URL template to use with <Image />:
To request a specific size, pass a size parameter of the form 123w, 123x123, or original:
Best practices
Set sizes
Wherever you can, use the sizes prop of <Image /> to describe how the image’s size varies with the viewport:
From sizes, the component generates a srcset of CDN URLs, so the browser loads the resolution that fits the shopper’s screen.
Query urlTemplate
When fetching image URLs using the GraphQL Storefront API, a typical url field takes width (and optionally height) as an argument:
With a size specified, the returned URL looks like this:
This CDN URL works with <Image />, but to get responsive images, query the urlTemplate field instead (available on the GraphQL Image type):
The returned URL has a size placeholder instead of a fixed size:
<Image /> uses this URL template to generate a srcset of CDN URLs that matches your sizes configuration.