diff --git a/packages/www/public/features/optimize-images/source/index.html b/packages/www/public/features/optimize-images/source/index.html index 08d0375..ad27995 100644 --- a/packages/www/public/features/optimize-images/source/index.html +++ b/packages/www/public/features/optimize-images/source/index.html @@ -9,6 +9,9 @@ + + +

Responsive images generation

The right image size will be used by the browser based on the device of @@ -39,6 +42,13 @@

picture_screenshot.png

Girl listening to music +

Picture tag with media sources

+ + + + Image + +

IMG tag

JPEG image

diff --git a/packages/www/public/features/optimize-images/source/long-cat.jpg b/packages/www/public/features/optimize-images/source/long-cat.jpg new file mode 100644 index 0000000..5fc9655 Binary files /dev/null and b/packages/www/public/features/optimize-images/source/long-cat.jpg differ diff --git a/packages/www/public/features/optimize-images/source/tall-cat.jpg b/packages/www/public/features/optimize-images/source/tall-cat.jpg new file mode 100644 index 0000000..a1739d8 Binary files /dev/null and b/packages/www/public/features/optimize-images/source/tall-cat.jpg differ diff --git a/src/optimize.ts b/src/optimize.ts index fadd2fb..89b32e4 100755 --- a/src/optimize.ts +++ b/src/optimize.ts @@ -673,7 +673,7 @@ async function processImage( const sizes = img.attr('sizes'); - for (const s of sourcesToGenerate) { + for (const s of sourcesToGenerate.reverse()) { const sourceWithThisMimeType = picture.children( `source[type="${s.mime}"]` ); @@ -701,17 +701,8 @@ async function processImage( const source = ``; - picture.prepend(source); + img.before(source); // Append before this way existing sources are always top priority } - - // Reorder sources to priority order 1)avif 2)webp - // - function popupSource(type: ImageMimeType): void { - const nodes = picture.children(`source[type="${type}"]`); - picture.prepend(nodes); - } - popupSource('image/webp'); - popupSource('image/avif'); } } }