Closed gajus closed 8 years ago
Hey @gajus
What about serving the first images above the fold as normal images?
What about serving the first images above the fold as normal images?
That assumes that server-side knows which images are above the fold. There is no way for server-side to know that.
True. But you could still load the first X images as regular images.
What about loading some of the content async to make document load faster?
True. But you could still load the first X images as regular images.
That assumes that the first images in the document are the same images that are visible in the initial viewport.
What about loading some of the content async to make document load faster?
This consideration is out of scope for Blazy. Frontend enhancement of any kind must not depend on the backend implementation.
Regardless, I am happy with the solution we implemented (that I have shared in the original post). I have shared it as a gesture of goodwill in hopes that it might prove useful to others.
Regarding your solution I would use setTimeout instead of setInterval to ensure that you only revalidates blazy once per interval.
And thanks for sharing gajus
Regarding your solution I would use setTimeout instead of setInterval to ensure that you only revalidates blazy once per interval.
Where do you see setInterval
in my code?
It even has a comment to explain why I am not using setInterval
.
/**
* The reason for using setTimeout instead of setInterval
* is to not re-run revalidate more often than the body
* of the function can be evaluated.
*/
Ha. Great. I need sleep or vacation. Looking at it on my phone and was sure I saw setInterval but good you're not using it
I am working on a large website (very large, HTML alone is 1MB). When I have added image lazy loading, initially it has been added after
DOMContentLoaded
event is fired. This caused the first image not to appear for a relatively long time.The solution I have ended up with is initialising Blazy as the first thing in the document and then revalidating Blazy state every 100 ms. This makes the first images to load as soon as they are added to the DOM.
Here is how it looks: