Optimize local images

jampack optimizes local images for faster download on any device and better Core Web Vitals scores.

  • Compresses images using better compressors or modern formats.
  • Generates responsive image sets for smaller devices.
  • Adds image dimensions if missing to avoid CLS issues.
  • Sets images to lazy loading (with exceptions)

<img> tags

<img src="./redpanda.jpg" alt="Red panda">

becomes

<img src="./redpanda.jpg.webp" alt="Red panda" 
     srcset="./redpanda.jpg.webp 3872w, ./[email protected] 3572w, ./[email protected] 3272w, ./[email protected] 2972w, ./[email protected] 2672w, ./[email protected] 2372w, ./[email protected] 2072w, ./[email protected] 1772w, ./[email protected] 1472w, ./[email protected] 1172w, ./[email protected] 872w"
     sizes="100vw"
     loading="lazy"
     decoding="async"
     width="3872" 
     height="2592">

src image is compressed

srcset of smaller images are generated

jampack will generate a set of smaller images by reducing the width of the images by steps of 300px.

In other words, you can have a single image in your static site and jampack will create the different smaller versions to serve the most optimized image for smaller devices.

If srcset is already present in source <img> then nothing is done and images are just compressed in PASS 2.

Responsives sizes

You can set sizes attribute to fine tune image selection in the srcset. See sizes attributes for more details.

sizes="100vw" will be added by default when srcset is set.

Lazy loading

jampack will set all images to load in lazy by default. This gives the browser the opportunity to load more critical data instead.

Images will have new attributes:

  • loading="lazy"
  • decoding="async"

Exceptions

Images will not be lazy loaded in the following conditions:

  • Image has attribute loading="eager". Explicitly requesting for no lazy loading.
  • Image is marked above the fold.

Note

Lazy loading images above the fold can cause LCP issues, we recommend to use the jampack’s <the-fold> feature or mark images with loading="eager" for images above the fold.

Sets width and height attributes

jampack will set image dimensions to avoid CLS issues.

jampack will also fix images with invalid format for attributes width or height.

<picture> tags

jampack will enrich <picture> tags with AVIF and WebP sources when they are missing.

<picture>
    <img src="./redpanda.jpg" alt="Red panda">
</picture>

will become

<picture>
    <source type="image/avif" srcset="./[email protected] 1936w, ./[email protected] 1636w, ./[email protected] 1336w, ./[email protected] 1036w, ./[email protected] 736w">
    <source type="image/webp" srcset="./[email protected] 1936w, ./[email protected] 1636w, ./[email protected] 1336w, ./[email protected] 1036w, ./[email protected] 736w">
    <img src="./redpanda.jpg" alt="Red panda" loading="lazy" decoding="async" width="1936" height="1296" srcset="./redpanda.jpg 1936w, ./[email protected] 1636w, ./[email protected] 1336w, ./[email protected] 1036w, ./[email protected] 736w" sizes="100vw">
</picture>

If the original image is lossless (PNG or WebP lossless) then:

  • The WebP image set will be compressed with near_lossless option.
  • No AVIF image set will be created because AVIF lossless is not very good (1) 2.

If the original image is lossly (JPEG or WebP lossly) then:

  • The AVIF image set will be compressed with normal quality settings.
  • The WebP image set will be lossly compressed.

Demo

SOURCE

JAMPACKED

_jampackimg_bass.svg1891img_bass.svg1891img_bass.svg.svg1446img_jam.svg6731img_jam.svg6731img_jam.svg.svg5339img_music.png142036img_music.png142036img_music.png.webp58184img_screenshot.png503173img_screenshot.png503173img_screenshot.png.webp172990img_water.jpg1954704img_water.jpg1954704img_water.jpg.jpg1106200[email protected]229140[email protected]347991[email protected]480733[email protected]628104[email protected]782791[email protected]946290[email protected]128497index.html1491index.html4026picture_music.png142036picture_music.png142036picture_music.png.webp58184picture_redpanda.jpg799292picture_redpanda.jpg799292picture_redpanda.jpg.jpg259873[email protected]91290[email protected]140307[email protected]197635picture_screenshot.png503173picture_screenshot.png503173picture_screenshot.png.webp172990[email protected]172990

SOURCE

  • img_bass.svg1891
  • img_jam.svg6731
  • img_music.png142036
  • img_screenshot.png503173
  • img_water.jpg1954704
  • index.html1491
  • picture_music.png142036
  • picture_redpanda.jpg799292
  • picture_screenshot.png503173

JAMPACKED

SourceOpen in new tab
JampackedOpen in new tab
Terminal
__                                    __    
    |__|____    _____ ___________    ____ |  | __
    |  \__  \  /     \\____ \__  \ _/ ___\|  |/ /
    |  |/ __ \|  Y Y  \  |_> > __ \\  \___|    < 
/\__|  (____  /__|_|  /   __(____  /\___  >__|_ \
\______|    \/      \/|  |       \/     \/     \/
 v0.23.4              |__| by β€Ήdivβ€ΊRIOTS

Options:
{ onlyoptim: true }


 PASS 1 - Optimizing 
β–Ά index.html
Done: 12.458s

 Summary 
╔════════════╀════════════╀══════════╀════════════╀════════════╗
β•‘ Action     β”‚ Compressed β”‚ Original β”‚ Compressed β”‚       Gain β•‘
β•Ÿβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β•’
β•‘ jpg->jpg   β”‚      2 / 2 β”‚  2.63 MB β”‚    1.30 MB β”‚   -1.32 MB β•‘
β•‘ png->webp  β”‚      5 / 5 β”‚  1.37 MB β”‚  508.33 KB β”‚ -890.55 KB β•‘
β•‘ svg->svg   β”‚      2 / 2 β”‚  8.42 KB β”‚    6.63 KB β”‚   -1.79 KB β•‘
β•‘ svg->embed β”‚      1 / 1 β”‚  1.85 KB β”‚    1.41 KB β”‚  -445.00 B β•‘
β•Ÿβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β•’
β•‘ Total      β”‚    10 / 10 β”‚  4.00 MB β”‚    1.81 MB β”‚   -2.20 MB β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•§β•β•β•β•β•β•β•β•β•β•β•β•β•§β•β•β•β•β•β•β•β•β•β•β•§β•β•β•β•β•β•β•β•β•β•β•β•β•§β•β•β•β•β•β•β•β•β•β•β•β•β•


 Issues 

β–Ά index.html

 fix  Adding missing  to the top of the 


 1 issue(s) over 1 files