Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support srcset for multiple image formats #1241

Closed
DanielHeath opened this issue Nov 15, 2016 · 4 comments
Closed

Support srcset for multiple image formats #1241

DanielHeath opened this issue Nov 15, 2016 · 4 comments

Comments

@DanielHeath
Copy link

We're using photoswipe and would like to serve webp images to chrome users.

I've considered the following options:

  • Compute a different the URL if webp is supported (doesn't play nice with server rendering)
  • Make the same URL return webp if the requesting browser is chrome (doesn't play nice with major CDN providers)
  • Use <picture> <source srcset="..." type="image/webp" /> (doesn't work with PhotoSwipe)

Would a PR introducing support for multiple image formats be welcome?

@dimsemenov
Copy link
Owner

Well, you can already serve webp in PhotoSwipe, either serve the image from server side based on headers, or detect webp support via JS (with something like Modernizr) and just rewrite the URL, e.g. like so:

pswp.listen('gettingData', function(index, item) {
  if (supportsWebp) {
    item.src = item.src.replace('.jpg', '.webp');
  } 
});

@DanielHeath
Copy link
Author

Right - as I listed in the options considered:

  • Serve the image from server side based on headers: This doesn't work with Akamai, Cloudflare or Cloudfront if you want caching. Using a CDN isn't some obscure use case; it's how most of the internet works.
  • Detect webp support via JS: This is a performance disaster as your images don't start to load until after your JS runs.

@dimsemenov
Copy link
Owner

Not quite understand your second point, as PhotoSwipe is a JS library, and loads all images dynamically.

@dimsemenov
Copy link
Owner

closed by v5 #1749

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants