Hi Arno,
First of all thank you for your plugin. I really like it, am an avid follower of photoswipe, using it in its pure form a lot. Now I am working on a WordPress site and am trying to get responsive images going for the slideshow.
I use the following responsive picture syntax.
It is the Changing image sizes, high-DPI images & different image types use case from here.
https://dev.opera.com/articles/responsive-images/
(Note this is not about art direction, where completely different images are served based on viewport.)
<picture>
<source
sizes="(min-width: 640px) 60vw, 100vw"
srcset="opera-200.webp 200w,
opera-400.webp 400w,
opera-800.webp 800w,
opera-1200.webp 1200w,
opera-1600.webp 1600w,
opera-2000.webp 2000w"
type="image/webp">
<img
src="opera-400.jpg" alt="The Oslo Opera House"
sizes="(min-width: 640px) 60vw, 100vw"
srcset="opera-200.jpg 200w,
opera-400.jpg 400w,
opera-800.jpg 800w,
opera-1200.jpg 1200w,
opera-1600.jpg 1600w,
opera-2000.jpg 2000w">
</picture>
This serves webp format images to browsers that support it and falls back to jpg format images for older browsers.
In fact I also combine this with lazysizes.
The whole thing then looks something like this.
<picture
><source
sizes="(min-width: 2700px) 1603px, (min-width: 1040px) calc(61.16vw - 36px), calc(100vw - 130px)"
data-srcset="image_19-2560x3327.jpg 2560w, image_19-2048x2661.jpg 2048w, image_19-1920x2495.jpg 1920w, image_19-1600x2079.jpg 1600w, image_19-1440x1871.jpg 1440w, image_19-1280x1663.jpg 1280w, image_19-1140x1481.jpg 1140w, image_19-1024x1331.jpg 1024w, image_19-960x1248.jpg 960w, image_19-900x1170.jpg 900w, image_19-800x1040.jpg 800w, image_19-768x998.jpg 768w, image_19-640x832.jpg 640w, image_19-525x682.jpg 525w, image_19-425x552.jpg 425w, image_19-320x416.jpg 320w, image_19-240x312.jpg 240w, image_19-180x234.jpg 180w, image_19-120x156.jpg 120w"
type="image/jpg"/>
<noscript><img src="image_19-2560x3327.jpg"/></noscript
><img
width="2560"
height="3327"
style="max-width: 2560px; max-height: 3327px;"
class="lazyload"
src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="
data-src="image_19-425x552.jpg"
alt=""
sizes="(min-width: 2700px) 1603px, (min-width: 1040px) calc(61.16vw - 36px), calc(100vw - 130px)"
data-srcset="image_19-2560x3327.jpg 2560w, image_19-2048x2661.jpg 2048w, image_19-1920x2495.jpg 1920w, image_19-1600x2079.jpg 1600w, image_19-1440x1871.jpg 1440w, image_19-1280x1663.jpg 1280w, image_19-1140x1481.jpg 1140w, image_19-1024x1331.jpg 1024w, image_19-960x1248.jpg 960w, image_19-900x1170.jpg 900w, image_19-800x1040.jpg 800w, image_19-768x998.jpg 768w, image_19-640x832.jpg 640w, image_19-525x682.jpg 525w, image_19-425x552.jpg 425w, image_19-320x416.jpg 320w, image_19-240x312.jpg 240w, image_19-180x234.jpg 180w, image_19-120x156.jpg 120w"
/></picture>
You might be curious about having the width
and height
attributes in there, well this is because of this upcoming feature. It helps with reducing page jank.
Regardless of all this, when I wrap this picture element into a link so that it can be shown through your excellent lightbox-photoswipe plugin I have to use the biggest source of that image, because if I don't, and the user is on a moderately large desktop they will either see a too small and blurry or a too large and blurry image in the slideshow. This is because the image dimensions need to be specified with the data attributes. For desktop this is not an issue. But..
This of course leads to loading huge images to users on mobile devices. So while the responsive picture element syntax takes care of that with having all the possible src
and srcset
attribute values, this is a bit trickier to accomplish when I like to use responsive images in the slideshow.
Short, how do you get responsive images for the slideshow going with your plugin? I can see in the photoswipe documentation that the native picture
element and the srcset
attribute are not supported. And they don't need to be supported. The picture
element is merely the thumbnail that then opens the slideshow. On a large screen this thumbnail has a large size and on mobile it is small.
I guess all this leads to the following question. How could I generate or populate this slide object with the already existing sizes and then feed those to your plugin? More than happy to help you write code, frontend or backend, for this. What do you think?