UNPKG

vanilla-lazyload

Version:

A fast, lightweight script to load images as they enter the viewport. SEO friendly, it supports responsive images (both srcset + sizes and picture) and progressive JPEG

14 lines (10 loc) 384 B
export const replaceExtToWebp = (value, condition) => condition ? value.replace(/\.(jpe?g|png)/gi, ".webp") : value; export const detectWebp = () => { var webpString = "image/webp"; var canvas = document.createElement("canvas"); if (canvas.getContext && canvas.getContext("2d")) { return canvas.toDataURL(webpString).indexOf(`data:${webpString}`) === 0; } return false; };