Closed cortix closed 1 year ago
It looks to me like your JPT configuration is fine and it is generating the correcf output, but from here your javascript lazy loading library should take the data-srcset
attribute and copy it to a srcset
attribute. Which lazy loading library are you using? I'd dig into that, make sure it's set up correctly.
So sorry, totally my misunderstanding. I thought that in the background jpt takes care of necessary dependencies. I felt really bad :)
Now it works. Here the settings;
I added lazysizes.min.js
inside in the <head></head>
;
<script src="{{ site.url }}{{ site.baseurl }}/assets/js/lazysizes.min.js" async="" ></script>
Then I updated the preset as follows.
presets:
default:
markup: data_auto
formats: [webp, original]
widths: [200, 400, 800, 1200, 1600]
data_sizes: false
attributes:
img: 'class="lazyload"'
Finally, this is the result;
<picture>
<source data-srcset="/assets/images/generated/2022-02-23-imperative-declarative-programming-in-java/forloops-200-f2d1de698.webp 200w, /assets/images/generated/2022-02-23-imperative-declarative-programming-in-java/forloops-400-f2d1de698.webp 400w, /assets/images/generated/2022-02-23-imperative-declarative-programming-in-java/forloops-800-f2d1de698.webp 800w, /assets/images/generated/2022-02-23-imperative-declarative-programming-in-java/forloops-1200-f2d1de698.webp 1200w, /assets/images/generated/2022-02-23-imperative-declarative-programming-in-java/forloops-1600-f2d1de698.webp 1600w" type="image/webp" srcset="/assets/images/generated/2022-02-23-imperative-declarative-programming-in-java/forloops-200-f2d1de698.webp 200w, /assets/images/generated/2022-02-23-imperative-declarative-programming-in-java/forloops-400-f2d1de698.webp 400w, /assets/images/generated/2022-02-23-imperative-declarative-programming-in-java/forloops-800-f2d1de698.webp 800w, /assets/images/generated/2022-02-23-imperative-declarative-programming-in-java/forloops-1200-f2d1de698.webp 1200w, /assets/images/generated/2022-02-23-imperative-declarative-programming-in-java/forloops-1600-f2d1de698.webp 1600w">
<source data-srcset="/assets/images/generated/2022-02-23-imperative-declarative-programming-in-java/forloops-200-09592ad47.jpeg 200w, /assets/images/generated/2022-02-23-imperative-declarative-programming-in-java/forloops-400-09592ad47.jpeg 400w, /assets/images/generated/2022-02-23-imperative-declarative-programming-in-java/forloops-800-09592ad47.jpeg 800w, /assets/images/generated/2022-02-23-imperative-declarative-programming-in-java/forloops-1200-09592ad47.jpeg 1200w, /assets/images/generated/2022-02-23-imperative-declarative-programming-in-java/forloops-1600-09592ad47.jpeg 1600w" type="image/jpeg" srcset="/assets/images/generated/2022-02-23-imperative-declarative-programming-in-java/forloops-200-09592ad47.jpeg 200w, /assets/images/generated/2022-02-23-imperative-declarative-programming-in-java/forloops-400-09592ad47.jpeg 400w, /assets/images/generated/2022-02-23-imperative-declarative-programming-in-java/forloops-800-09592ad47.jpeg 800w, /assets/images/generated/2022-02-23-imperative-declarative-programming-in-java/forloops-1200-09592ad47.jpeg 1200w, /assets/images/generated/2022-02-23-imperative-declarative-programming-in-java/forloops-1600-09592ad47.jpeg 1600w">
<img class=" ls-is-cached lazyloaded" data-src="/assets/images/generated/2022-02-23-imperative-declarative-programming-in-java/forloops-800-09592ad47.jpeg" alt="for loops example" src="/assets/images/generated/2022-02-23-imperative-declarative-programming-in-java/forloops-800-09592ad47.jpeg">
</picture>
By the way, thanks for your help.
I might have missed something but believe or not I've read most of the documentation. I am trying to explain what I did again. If I'm wrong please correct me.
It's very clear what I want to do. My goal is to create lazy-loading images suitable for many different media formats.
As I understand from the docs and the discussions on repo, If I want to create lazy-loading images, I need
data-
attributes. Because of that I have chosendata_auto
markup. If I useauto
markup, I cannot use lazy loading lib. By the way, you already explained why the data tag is needed here.This time I kept things very simple.
{% picture 2022-02-23-imperative-declarative-programming-in-java/forloops.jpeg --alt for loops example %}
I tried to override default preset like above. As you can see, I only overrided 4 things.
According to this discussion, we have to set
data_sizes
asfalse
to able to get plainsizes
attribute instead ofdata-sizes
.When I use this preset, I can't see the
srcset
in the generated html. As you mentioned in your previous comment, I wasn't expecting to see it in the site file anyway. But I was expecting to see it in the html.in the html;
As a result, I am getting this;
Could you help me?