scaleflex / js-cloudimage-responsive

Cloudimage Responsive will smartly resize, compress and accelerate images across the World in your site for all devices. The plugin supports lazy loading technique with fancy animation on image load. Any questions or issues, please report to https://github.com/scaleflex/js-cloudimage-responsive/issues
Other
68 stars 15 forks source link

Allow ciResponsive.process to use a custom root element #17

Closed Nargonath closed 3 years ago

Nargonath commented 3 years ago

In some cases we trigger window.ciResponsive.process() on-demand to load images that were not present at the initial page load run. I noticed that the process function processes all images of the page every time it is called: https://github.com/scaleflex/js-cloudimage-responsive/blob/1012a0b52551ffec2fa70664a4c0d8acf7dc32aa/src/plain/ci.service.js#L54

I think this could be enhanced by providing a second argument to process which would be a Node element. This would be a non breaking change. That way we could use this parameter to change the root from which the querySelectorAll is performed. It would only search from a sub part of the DOM rather than the whole document every time. This would prevent unnecessary work in our use case. If not provided the current behavior would remain.

What do you think? I'd be happy to open a PR for it if that's an enhancement you'll accept.

Thank you.

dzmitry-stramavus commented 3 years ago

hey @Nargonath ,

Sure, it's a great enhancement proposition. And your PR will be kindly checked and merged :)

Feel free to ask any questions or help