Skip to content

Commit 2916e52

Browse files
authored
Merge pull request #21 from peerigon/feat/filestack-auto-image
feat: Use auto_image transform from Filestack
2 parents 27e55fe + cf516fa commit 2916e52

File tree

1 file changed

+4
-25
lines changed

1 file changed

+4
-25
lines changed

src/index.js

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,6 @@ const inImageCache = ({ handle }, shouldCache) => {
1919
return false
2020
}
2121

22-
// check webp support
23-
let isWebpSupportedCache = null
24-
const isWebpSupported = () => {
25-
if (isWebpSupportedCache !== null) {
26-
return isWebpSupportedCache
27-
}
28-
29-
const elem =
30-
typeof window !== `undefined` ? window.document.createElement(`canvas`) : {}
31-
if (elem.getContext && elem.getContext(`2d`)) {
32-
isWebpSupportedCache =
33-
elem.toDataURL(`image/webp`).indexOf(`data:image/webp`) === 0
34-
return isWebpSupportedCache
35-
}
36-
return false
37-
}
38-
3922
// Add IntersectionObserver to component
4023
const listeners = []
4124
let io
@@ -75,16 +58,12 @@ const bgColor = backgroundColor =>
7558
const resizeImage = ({ width, height, fit }) =>
7659
`resize=w:${width},h:${height},fit:${fit}`
7760

78-
const compressAndWebp = webp => `${webp ? 'output=format:webp/' : ''}compress`
61+
// Filestack supports serving modern formats (like WebP) for supported browsers.
62+
// See: https://www.filestack.com/docs/api/processing/#auto-image-conversion
63+
const compressAndWebp = webp => `${webp ? 'auto_image/' : ''}compress`
7964

8065
const constructURL = (handle, withWebp, baseURI) => resize => transforms =>
81-
[
82-
baseURI,
83-
resize,
84-
...transforms,
85-
compressAndWebp(isWebpSupported() && withWebp),
86-
handle
87-
].join('/')
66+
[baseURI, resize, ...transforms, compressAndWebp(withWebp), handle].join('/')
8867

8968
// responsiveness transforms
9069
const responsiveSizes = size => [

0 commit comments

Comments
 (0)