Skip to content

Commit

Permalink
Fix generated <source> elements within <picture>, removing 'src' tag
Browse files Browse the repository at this point in the history
  • Loading branch information
OliverO2 committed Mar 24, 2022
1 parent 9fe77e3 commit cd05734
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Modern image formats such as WebP can drastically reduce image download sizes wh
For each alternative image format, the plugin expects an image file with the alternative's extension (e.g. `.webp`) next to the corresponding base image file (typically JPEG or PNG). It will then prefer the alternative image if the browser supports it.

To use alternative _background_ images, each page's `<html>` element must provide classes identifying browser support for alternative formats (e.g. `<html class="webp">`). You can use the provided Twig function `html_image_support_classes()` to achieve this (e.g. `<html class="{{ html_image_support_classes() }}>"`) for `webp` and `avif` formats, or use your own detection mechanism.
To use alternative _background_ images, each page's `<html>` element must provide classes identifying browser support for alternative formats (e.g. `<html class="webp">`). You can use the provided Twig function `html_image_support_classes()` to achieve this (e.g. `<html class="{{ html_image_support_classes() }}">`) for `webp` and `avif` formats, or use your own detection mechanism.
> :information_source: JavaScript detection, such as the one provided by [Modernizr](https://modernizr.com/download?webp-setclasses&q=webp), might not complete before images start to load. In this case, images can load twice, in different formats.
Expand Down
2 changes: 1 addition & 1 deletion twig/ResponsiveImagesExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function imageElement(array $context, string $path, ?string $baseWidth =
foreach ($this->alternativeFormats as $alternativeFormat) {
$imageUrl = alternativeFormatUrl($baseImageUrl, $alternativeFormat);
$srcsetAttribute = $this->srcsetAttribute($descendingImageWidths, $imageVector, $alternativeFormat);
$result .= " <source type=\"image/$alternativeFormat\" src=\"$imageUrl\"$srcsetAttribute$sizesAttribute>\n";
$result .= " <source type=\"image/$alternativeFormat\"$srcsetAttribute$sizesAttribute>\n";
}
}

Expand Down

0 comments on commit cd05734

Please sign in to comment.