respimagelint
respimagelint copied to clipboard
dinamically generated images are ignored
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?
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.
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&f=webp 1x,
https://app.local:8890/viewer/34262?bb=708x&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
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?
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
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
👍
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
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.
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)
Would it be possible to use
srcdoc
ordata:text/html...
assrc
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?
ok, I'll get a try
Thanks
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.