New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add lazy load attribute for images #3961
Comments
This seems like a reasonable request and therefore will support it. However, since lazy is a switch, it should be declared as an option.
or
The converter would still output the I will accept a PR to include this in Asciidoctor 2.1.x. |
Thank you for accepting the request! The The syntax that I had suggested:
|
That's true, but eager is the default. So there's no point specifying it. That's what allows us to look at "lazy" as a switch. |
That might introduce problems in the future if browsers decide to add a third possible value. |
At that point, we could introduce an attribute. But since no such value is anywhere in sight, I think we would be overdesigning by trying to accommodate it. |
If this is an attribute, it can also be declared globally as |
Yes there is. It would be |
Hmm and how would it be overridden (added/removed) for one instance? |
You'd need to unset the attribute using an attribute entry, then set it again below the element. There's currently no way to indicate that an option be turned off on an element. That's something we hope to add to the language in the future. |
In that case, I think an attribute will result in cleaner markup? To allow switch-like behaviour, |
@mojavelinux any update on the issue? |
I'd be open to a PR. This issue is not a priority for me, but I will help push it through if you do the implementation and docs. |
While this new feature is being developed, is there a way to add these attributes to images somewhere else before the generation of the HTML file? |
@arturo32 for now, we are using a very hacky regex
|
Thank you very much! I think that will do! |
Happy to help, but I can't vouch for using that for anything mission critical. |
It would be much cleaner to use a postprocessor extension. See https://docs.asciidoctor.org/asciidoctor/latest/extensions/postprocessor/. You could also extend the converter and override convert_image or convert_inline_image. See https://docs.asciidoctor.org/asciidoctor/latest/convert/custom/ |
IMHO it would be nice to have a general option to make all images lazy. We currently use the following slim extension:
AFAICS this works fine. |
The
loading="lazy"
attribute for lazy loading images should be supported by Asciidoctor for HTML sites. (MDN)Eg:
Lazy loading images increases the performance of the site.
The browser will handle the lazy loading of images. The attribute is supported in the major browsers as well. The support will only increase, so I think it is a good feature that can be added.
The text was updated successfully, but these errors were encountered: