Last active
March 19, 2019 16:16
-
-
Save dane-stevens/028051a315c7caea9e7027b047ecbb0f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Img extends React.Component { | |
constructor(props) { | |
... | |
this.window = typeof window !== 'undefined' && window | |
this.isWebpSupported = this.isWebpSupported.bind(this) | |
} | |
... | |
isWebpSupported() { | |
if (!this.window.createImageBitmap) { | |
return false; | |
} | |
return true; | |
} | |
render() { | |
... | |
// If a format has not been specified, detect webp support | |
// Set the fm (format) option in the image URL | |
if (!options['fm'] && this.isWebpSupported) { | |
options['fm'] = 'webp' | |
} | |
... | |
return ( | |
... | |
) | |
} | |
} | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment