yireo / Yireo_NextGenImages

44 stars 26 forks source link

Support of background images #5

Open avstudnitz opened 3 years ago

avstudnitz commented 3 years ago

Just to be sure: background images are not supported, right? We are using code like this in custom widgets:

<div class="" style="background-image: url(<?= $escaper->escapeHtmlAttr($image) ?>);">...</div>

We might implement it if it doesn't exist already.

avstudnitz commented 3 years ago

Seems JPG fallback support will be tricky then...

jissereitsma commented 3 years ago

No, they are not supported. It is tricky anyway. The picture element is the main trick as of yet. I have been working myself on a non-Magento site with a PHP script that generates a base64-encoded string for the image and then uses a cookie to switch in between, but this is not ideal either. With Full Page Caching in mind, the solution either requires JavaScript and some cookie-magic (ugly), or a solution like picture ...

avstudnitz commented 3 years ago

There might be a native solution for that in the future: see https://raoulkramer.de/avif-webp-images-css-background-usage-progressive-enhanced-with-image-set/.

jissereitsma commented 3 years ago

Hmm, that's still a loooong wait :(