window.onscroll = async () => { const scrollHeight = document.documentElement.scrollHeight const scrollTop = document.documentElement.scrollTop const clientHeight = document.documentElement.clientHeight if (scrollTop + clientHeight > scrollHeight - 5) { // .. API async Fetch } }