dimsemenov / PhotoSwipe

JavaScript image gallery for mobile and desktop, modular, framework independent
http://photoswipe.com
MIT License
24.18k stars 3.31k forks source link

Using srcset for images causes images to reload multiple times if you resize the screen #2035

Closed thienedits closed 1 year ago

thienedits commented 1 year ago

I think its because the img "sizes" attribute is being continually updated as you resize the viewport

You can try on the demo site here: https://dromru.github.io/react-photoswipe-gallery/?path=/story/demo-srcset--srcset

View my screenshots below with network requests increasing.

Initial size: Screen Shot 2023-04-04 at 10 47 15 PM

After resizing, making the image scale in size: Screen Shot 2023-04-04 at 10 47 40 PM

dimsemenov commented 1 year ago

That looks like an old version of PhotoSwipe that I do not support anymore.

thienedits commented 1 year ago

Hi @dimsemenov, I still see the issue with photoswipe 5.3.7. I created a codesandbox here

https://codesandbox.io/p/sandbox/trusting-bush-ifv42d?file=README.md

dimsemenov commented 1 year ago

By your first screenshot, you disabled the cache in Chrome dev tools, that's why srcset is requested every time.

thienedits commented 1 year ago

Ah ok I didn't realize that how it works with srcset, thanks.