RFC: Picture Tag - CldSource #511
Replies: 2 comments 3 replies
-
Hey there, great RFC! I have some comments for it. Also related issue in Nuxt Cloudinary repo nuxt-modules/cloudinary#160 I would go with the solution you mentioned at the end - a native In Nuxt Image example, Image component is mostly used in comparison to Picture. The Picture seems like a legacy feature that needs to be mainatined because everyone seems to be using image. Maybe a better solution would be a docs FAQ / Guide about using Picture and Source tags (native solutions) to achieve this? This is what I am using in Nuxt Security for example -> https://nuxt-security.vercel.app/documentation/advanced/strict-csp As my friend used to say -> the best code is the one that you have not writted (you don't need to maintain it, it does not have bugs, etc :D ) So in summary, my recommendation would be to write a docs section for each of the supported frameworks by CLD (Next, Nuxt, Astro, Svelte) about using native WDYT? :) |
Beta Was this translation helpful? Give feedback.
-
Maybe an implementation from Astro could be helpful here as well :) |
Beta Was this translation helpful? Give feedback.
-
The HTML picture tag gives developers more control over how their images display, including art direction and using media queries to define different versions of images like light mode and dark mode.
This contrasts to the image tag's sizes and srcet, which allow you to specify different sizes of a single image.
Part of Cloudinary's toolset is being able to transform images on-the-fly, where coupled with the picture tag, can result in an easy way to provide different versions of images based on a single source.
Related Issue: #42
Proposal
The picture tag composition is defined by three separate tags: picture, source, and img.
<picture>
wraps a series of<source>
tags and a single<img>
tag to allow configuration of what image you want to display and when.In creating a solution, we want to maintain the flexibility and patterns of the native picture tag while exposing the advanced capabilities in an intuitive way, leaving the option of replicating the existing composition the ideal solution.
Basic Usage
The
CldSource
components would use the Next.jsgetImageProps
function to assists with srcset generation.The CldSource component would be the addition, where given the
<picture>
tag wouldn't have any function, at this time, it might not make sense to expose aCldPicture
tag.Alternative Options
With a little exploration on potential options for supporting this...
Unpic handles this with Source components, but not a Picture component: https://unpic.pics/blog/introducing-unpic-picture-tags/
While it feels slightly odd to not have a
<CldPicture>
component, given it wouldn't have any function, it doesn't make sense to create it.Nuxt has a NuxtPicture, but my understanding is it's really meant for formats, and the syntax is encapsulated into the main component, not sources like Unpic: https://image.nuxt.com/usage/nuxt-picture
Astro similarly does what NuxtPicture does, really relying on it only for formats: https://docs.astro.build/en/guides/images/#picture-
Next.js relies on
getImageProps
, which isn't really first class picture support: https://nextjs.org/docs/app/api-reference/components/image#getimagepropsWhile there is some merit to potentially having a
<CldPicture
tag with an array of options as asources
prop for instance, I think following along with the native<picture>
composition will be the most intuitive and practical from an education perspective and "embracing the web".Beta Was this translation helpful? Give feedback.
All reactions