This can be short-circuited, meaning as soon as we find an element outside and below the viewport (starting from the top), we can assume that all proceeding elements (below it) are also outside the viewport. It might work better as a setInterval instead of scroll listener, as that would help us avoid loading elements that are skipped if the user uses the ToC to skip to a specific section.
This should help a lot with the initial loading time of the page. Might be difficult to make it work smoothly though.
https://stackoverflow.com/questions/123999/how-can-i-tell-if-a-dom-element-is-visible-in-the-current-viewport/7557433#7557433
This can be short-circuited, meaning as soon as we find an element outside and below the viewport (starting from the top), we can assume that all proceeding elements (below it) are also outside the viewport. It might work better as a setInterval instead of scroll listener, as that would help us avoid loading elements that are skipped if the user uses the ToC to skip to a specific section.