HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
lazy loading images
Hey all!
Do you know how to lazy load images on your vanilla forum?
I'm thinking to develop an addon for that because web performance is important now for seo and user experience...Maybe someone is working on it or has made some code....
Tagged:
0
Comments
the first thing i can do is to add loading="lazy" to <img> elements for chrome users...
And that should about do it.
This will inevitably come to other browsers as well, so I wouldn't waste time to implement something, that will have as native solution everywhere soon.
https://bugzilla.mozilla.org/show_bug.cgi?id=1542784
My themes: pure | minusbaseline - My plugins: CSSedit | HTMLedit | InfiniteScroll | BirthdayModule | [all] - PM me about customizations
VanillaSkins.com - Plugins, Themes and Graphics for Vanillaforums OS
Don't CDN's like Cloudflare account for things such as image loading and caching? That is of course; if you pointing to them.
quick win : edit C:\projets\routeur4g.fr\discussions\library\core\functions.render.php
edit line 1099 and add loading="lazy"
return '<img loading="lazy" src="'.htmlspecialchars($image, ENT_QUOTES).'"'.$attributes.' />';
But only dashboard images are changed.
For discussions and comments images, i add in database loading="lazy" to img elements but it's stripped by vanilla.
Do you have an idea where i can allow loading="lazy" attribute or add it after vanilla stripped it?
At before_render, I imagine you can grab the discussion/comment content and run a search through it, str_replace <img with <img loading="lazy" .
That'd be the crude but possible way. Or us php html_element to manipulate the above mentioned content, find every img element and add the said attribute.
As for new images, you can tell vanilla to not strip that loading attribute upon render. Look for htmlawed
I went ahead and created a quick plugin for this:
I used
FormatUtil::replaceButProtectCodeBlocks
but am open to suggestions and may expand it in the future to usehtml_element
as @donshakespeare has suggested, in case this feature doesn't ship in vanilly core soon.My themes: pure | minusbaseline - My plugins: CSSedit | HTMLedit | InfiniteScroll | BirthdayModule | [all] - PM me about customizations
VanillaSkins.com - Plugins, Themes and Graphics for Vanillaforums OS
Bleistivt you’re top! I will try it this afternoon or tomorrow ! Thank you!