Show HN: The smallest and most narcissistic image lazyloading JavaScript library
1–10 of 10 posts
Re: Show HN: The smallest and most narcissistic image lazyloading JavaScript library
#2It is build with JavaScript intersection observers. To keep it below 500 byte it currently only works with img tags, but I may adapt it for more HTML tags if that is useful.
I do not plan to add a lot of config options, as there are nice highly configurable lazy loading libraries out there. Mine should just be a script include and you are done :D
Re: Show HN: The smallest and most narcissistic image lazyloading JavaScript library
#3Re: Show HN: The smallest and most narcissistic image lazyloading JavaScript library
#4Use svg instead of that PNG and dataset not set/getattribute and you are down to 400
Re: Show HN: The smallest and most narcissistic image lazyloading JavaScript library
#5Use svg instead of that PNG and dataset not set/getattribute and you are down to 400
`data:image/svg+xml;utf8,svg{background" rel="nofollow">http://www.w3.org/2000/svg">svg{background: grey;}`
Re: Show HN: The smallest and most narcissistic image lazyloading JavaScript library
#6Use svg instead of that PNG and dataset not set/getattribute and you are down to 400
When I use the svg in the img src, the image is higher as the original and thereby the size changes on lazy loading. Do you have a clue why? Used svg: `data:image/svg+xml;utf8, svg{background" rel="nofollow">http://www.w3.org/2000/svg"> svg{background : grey;} `
And don't bother with the color there, just set a background-color on all IMG elements in CSS, the svg will be transparent.
Re: Show HN: The smallest and most narcissistic image lazyloading JavaScript library
#7Re: Show HN: The smallest and most narcissistic image lazyloading JavaScript library
#8Earlier quoted context omitted.
When I use the svg in the img src, the image is higher as the original and thereby the size changes on lazy loading. Do you have a clue why? Used svg: `data:image/svg+xml;utf8, svg{background" rel="nofollow">http://www.w3.org/2000/svg"> svg{background : grey;} `
Do something like: data:image/svg+xml, http://www.w3.org/2000/svg' viewBox='0 0 1 1' /> And don't bother with the color there, just set a background-color on all IMG elements in CSS, the svg will be transparent.
Re: Show HN: The smallest and most narcissistic image lazyloading JavaScript library
#9Some browsers like chrome support this functionality natively by setting the image attribute loading="lazy" ( https://web.dev/native-lazy-loading/ ) You could improve your library by adding a check wether the browser supports it natively, if yes use the loading attribute, if no use the visibility observer