ooade / pimg

:camera: Mini Image Lazy Loader for P(R)eact and Vue
https://pimg.surge.sh
MIT License
99 stars 11 forks source link

Handle placeholder generation #33

Closed luqmanoop closed 6 years ago

luqmanoop commented 6 years ago

What does this PR do?

Fixes a bug where a placeholder is being generated for wrong src assumed to be a Cloudinary image.

How to test this PR?

/*
* Before
* Given an image with src other than Cloudinary
* https://cdn.pexels.com/upload/2012/02/10/cloudinary__340.jpg
*/
if (src && src.includes('cloudinary')) { // matches
  ...
}

As stated in Cloudinary documentation here, the best way to test if the image is from Cloudinary is to check in the host

/*
* After
* Given an image with src other than Cloudinary
* https://cdn.pexels.com/upload/2012/02/10/cloudinary__340.jpg
*/
try {
  const srcURL = new URL(src)
  if (srcURL.host.includes('cloudinary')) { // does not match
    ...
  }
} catch(err) {}
ooade commented 6 years ago

Thanks. I'll look into this. It might take a while tho.

luqmanoop commented 6 years ago

Thanks for reviewing and merging. Cheers.