Optimize CDN images
jampack
can optionally optimizes CDN images for faster download on any device and better Core Web Vitals scores.
jampack
will use the transform capabilities of the CDN to resize the images for the srcsets. This doesnât require any download of the images.
Supported CDN providers
- Adobe Dynamic Media (Scene7)
- Builder.io
- Bunny.net
- Cloudflare
- Contentful
- Cloudinary
- Directus
- Imgix
- Unsplash
- DatoCMS
- Sanity
- Prismic
- Kontent.ai
- Netlify
- Shopify
- Storyblok
- Vercel / Next.js
- WordPress.com and Jetpack Site Accelerator
This feature is powered by unpic to detect and transform URLs. See unpicâs GitHub project for more details.
Configuration
image: {
cdn: {
process: 'off' | 'optimize',
},
}
process: | Description |
---|---|
'off' | It will ignore cdn images and treat them as external images. |
'optimize' | It will detect external images as coming from CDN and generate srcsets images url on the CDN. |
Example
<img>
and <picture>
elements with CDN images like:
<img
src="https://images.unsplash.com/photo-1513002749550-c59d786b8e6c?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D"
alt="Clouds in the sky by Taylor Van Riper"
width="2848"
height="4272"
/>
For the moment,
width
andheight
image attributes are mandatory forjampack
to work CDN images.
becomes
<img
src="https://images.unsplash.com/photo-1513002749550-c59d786b8e6c?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D"
alt="Clouds in the sky by Taylor Van Riper"
width="2848"
height="4272"
loading="lazy"
decoding="async"
srcset="
https://images.unsplash.com/photo-1513002749550-c59d786b8e6c?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&w=2848&fit=min&auto=format 2848w,
https://images.unsplash.com/photo-1513002749550-c59d786b8e6c?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&w=2548&fit=min&auto=format 2548w,
https://images.unsplash.com/photo-1513002749550-c59d786b8e6c?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&w=2248&fit=min&auto=format 2248w,
https://images.unsplash.com/photo-1513002749550-c59d786b8e6c?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&w=1948&fit=min&auto=format 1948w,
https://images.unsplash.com/photo-1513002749550-c59d786b8e6c?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&w=1648&fit=min&auto=format 1648w,
https://images.unsplash.com/photo-1513002749550-c59d786b8e6c?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&w=1348&fit=min&auto=format 1348w,
https://images.unsplash.com/photo-1513002749550-c59d786b8e6c?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&w=1048&fit=min&auto=format 1048w
"
sizes="100vw"
/>
Demo
SOURCE
JAMPACKED
_jampack index.html 526 index.html 505SOURCE
- index.html 526
JAMPACKED
- _jampack
- index.html 505
Terminal
__ __
|__|____ _____ ___________ ____ | | __
| \__ \ / \\____ \__ \ _/ ___\| |/ /
| |/ __ \| Y Y \ |_> > __ \\ \___| <
/\__| (____ /__|_| / __(____ /\___ >__|_ \
\______| \/ \/| | \/ \/ \/
v0.30.0 |__| by âčdivâșRIOTS
Options:
{ onlyoptim: true }
Merging default config with:
{
"image": {
"cdn": {
"process": "optimize"
}
}
}
PASS 1 - Optimizing
ⶠindex.html
Done: 26.592ms
â No issues