JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 20550
  • Score
    100M100P100Q145814F
  • License MIT

Instantly detect support for WEBP images in the browser in 0.2KB

Package Exports

  • supports-webp

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (supports-webp) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

supports-webp

Detect support for WEBP images in the browser in 0.3KB

gzipped size Travis build status gzipped size

Usage with npm and ES2015

npm install --save supports-webp
import supportsWebP from 'supports-webp';
// supportsWebP is a Promise

supportsWebP.then(supported => {
    if (supported) {
        console.log('Load WebP!')
    } else {
        console.log('Load JPEG!')
    }
});

// Or if you can use async/await:
if (await supportsWebP) {
    console.log('Load WebP!')
} else {
    console.log('Load JPEG!')
}

Usage without build tools

Copy the content of the file dist/supports-webp.min.js into your code, don't load that file separately, it's too small. Then:

window.supportsWebP.then(supported => {
    if (supported) {
        console.log('Load WebP!')
    } else {
        console.log('Load JPEG!')
    }
});