GithubHelp home page GithubHelp logo

biosboy / webp-checker Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 1.0 111 KB

:octopus: Tiny util for checking browser's webP support ability. Helps to understand is that :first_quarter_moon: browser has webp support or not :bell:

Home Page: https://www.npmjs.com/package/webp-checker

License: MIT License

JavaScript 53.90% TypeScript 46.10%
webp webp-checker webp-support html webp-images

webp-checker's Introduction

WebP Checker

Tweet

The easist way to check webp support in any browser!

npm Price License: MIT GitHub package version

logo_image

How to use:

  • Prepare: Install webp-checker as a regular node_modules package via:
  npm i web-checker

or yarn:

  yarn add web-checker

Important! - you need to run webp-checker as soon as possible inside the very first component/module that has an interaction with the whole DOM. For example in create-react-app you probably should run the below script example in the componentDidMount() method of the root App.js component (or if you're using Redux state managment inside its initialState.js).

Quick Start:

  • So, to understand if your browser has webP support or not, basically, you need just run webpChecker. After function running you will get a window variable __WEBPSUPPORT__ (e.g. window.__WEBPSUPPORT__) with boolean value that shows if the webp support is true/false.

-- Example for React usage:

  // ...some logic
  import webpChecker from 'webp-checker' // import it;

  class App extends React.Component {
   // ...some logic
   
   componentDidMount() {
       webpChecker(); // run checker
  
       window.__WEBSUPPORT__ // get notified about browser webp support by this global variable
   }
   
   // ...some logic
  }

-- Example basic:

   import webpChecker from 'webp-checker' // import it;

   webpChecker(); // run checker
  
   window.__WEBSUPPORT__ // get notified about browser webp support by this global variable

Advanced:

  • In case when you need to set up a better custom config you can throw props as:
  import webpChecker from 'webp-checker' // import it;

  const config = {
    imgURL: 'imgSrc', // your_webp_image_src, by default used google static image
    disableGlobal: true, // disable global injection in 'window' object, by default 'false'
    injectBodyClass: false, // explicitly set a 'body' class 'webp-support', by default 'true',
    callback: status => status // some callback that you want to return with webp checker result 'true/false'
  }
  
  webpChecker(config); // run checker

webp-checker's People

Contributors

biosboy avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

icodein

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.