Skip to content

Instantly share code, notes, and snippets.

@James-Bovis
Last active September 26, 2019 09:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save James-Bovis/6aaba3fe23e68a1f467d8214320aa121 to your computer and use it in GitHub Desktop.
Save James-Bovis/6aaba3fe23e68a1f467d8214320aa121 to your computer and use it in GitHub Desktop.
Using .webp images with correct fallback
<picture class="">
<source srcset="<%= asset_path('.../.../WEBP_ASSET.webp') %>" type="image/webp" />
<img src="<%= asset_path('../../FALLBACK_ASSET.jpg') %>" type="image/jpg" />
</picture>
// @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