respimagelint icon indicating copy to clipboard operation
respimagelint copied to clipboard

dinamically generated images are ignored

Open massimo-cassandro opened this issue 1 year ago • 11 comments

I've a tool that generates images dynamically server-side, and they are ignored by the linter. The src images do not contain the extension (e.g. webp, jpeg, etc.), could this be the problem?

sample url: https://.../34262

Generated images send the appropriate headers and work fine on all browser

Is it possible to make the linter also intercept images of this type?

massimo-cassandro avatar Sep 22 '23 08:09 massimo-cassandro

I've a tool that generates images dynamically server-side, and they are ignored by the linter.

What does that mean “they are ignored”?

Please post the HTML-Source code of one of the ignored images, your issue is probably not related to the image URLs but the HTML code instead.

ausi avatar Sep 22 '23 09:09 ausi

What does that mean “they are ignored”?

The linter returns 0 out of 0 images passed all checks. (but there are several)

This is a sample code:

<div class="imageWrapper_lRJJ3B borderBottom_sNMfJg">
  <picture
    ><source
      srcset="https://app.local:8890/viewer/34262?bb=354x&amp;f=webp 1x,
        https://app.local:8890/viewer/34262?bb=708x&amp;f=webp 2x"
      type="image/webp" />
    <img
      src="https://app.local:8890/viewer/34262?bb=370x"
      srcset="https://app.local:8890/viewer/34262?bb=370x 1x,
        https://app.local:8890/viewer/34262?bb=708x 2x"
      alt="Halloween e Foliage"
  /></picture>
</div>

Thanks for your support

massimo-cassandro avatar Sep 22 '23 09:09 massimo-cassandro

I just tried your example HTML code and got the expected 1 out of 1 images passed all checks. response from the linter.

Are your images already there after the page finished loading in the browser? Or are they dynamically created via JavaScript afterwards?

ausi avatar Sep 22 '23 09:09 ausi

The images were already there when I lauch the linter

I'll try to set up a test page for you to try. I'll try to send you the link later

massimo-cassandro avatar Sep 22 '23 09:09 massimo-cassandro

The images were already there when I lauch the linter

The linter reloads the current page into an <iframe> (in order to be able to resize the viewport), so the image has to be there on page load.

I'll try to set up a test page for you to try. I'll try to send you the link later

👍

ausi avatar Sep 22 '23 10:09 ausi

Trying to set up the test page, I realized what the problem is. It's what you had hypothesized at the beginning: the images do not exist in the code but in many cases they are injected by JS: this is the case of lazy images loading created via js libraries or in React ~, in dev mode~.

The ideal thing would be if the linter could acquire the generated html and not the hard-coded one only.

Thank you again for your help

massimo-cassandro avatar Sep 22 '23 10:09 massimo-cassandro

The ideal thing would be if the linter could acquire the generated html and not the hard-coded one only.

It already does that, but it only waits until the pages onload event. So if your script adds images after onload they cannot be found by the linter.

ausi avatar Sep 22 '23 11:09 ausi

if I understand correctly, the script generates an iframe with the page URL and then, once loading is complete, it runs the checks, thus excluding anything loaded asynchronously.

But couldn't it be possible to directly use the html code on the page?

Would it be possible to use srcdoc or data:text/html... as src value?

I would be happy to help you (if I'm able..., I haven't seen how the script is built)

massimo-cassandro avatar Sep 22 '23 11:09 massimo-cassandro

Would it be possible to use srcdoc or data:text/html... as src value?

That does not work, as all JavaScript events would get lost, and they are required for most pages as they often react to the window size and potentially affect the size of the images themselfs.

I would be happy to help you (if I'm able..., I haven't seen how the script is built)

You can find the code responsible for loading the iframe here: https://github.com/ausi/respimagelint/blob/194f75598b0fc0e26bb3166a17a3e5ecbb25f30b/src/collector/index.js#L28-L72

There is extra code that waits for all jQuery ajax requests (via jQuery.active), maybe we can add something similar for React?

ausi avatar Sep 22 '23 11:09 ausi

ok, I'll get a try

Thanks

massimo-cassandro avatar Sep 22 '23 12:09 massimo-cassandro

I ran into this with React too. Maybe a generic way to tell you the page is fully loaded? I tried setting jQuery = { active: 1 }; on the html and jQuery = { active: 0 }; after that, works sometimes but is a bit flaky.

mg-aceik avatar Dec 21 '23 01:12 mg-aceik