Last active
September 26, 2019 09:27
-
-
Save James-Bovis/6aaba3fe23e68a1f467d8214320aa121 to your computer and use it in GitHub Desktop.
Using .webp images with correct fallback
This file contains 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
<picture class=""> | |
<source srcset="<%= asset_path('.../.../WEBP_ASSET.webp') %>" type="image/webp" /> | |
<img src="<%= asset_path('../../FALLBACK_ASSET.jpg') %>" type="image/jpg" /> | |
</picture> |
This file contains 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
// @flow | |
import * as React from 'react' | |
import WEBP_ASSET_PATH from '../../../....webp' | |
import FALLBACK_ASSET_PATH from '../../../....jpg' | |
const renderWebpImage = (): React.Element<'picture'> => ( | |
<picture> | |
<source | |
className='' | |
srcSet={WEBP_ASSET_PATH} | |
type='image/webp' | |
/> | |
<img | |
alt='' | |
className='' | |
src={FALLBACK_ASSET_PATH} | |
/> | |
</picture> | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment