let key; const fn = () => { if(key) return; key = true; ....await fetch key = false; } $(window).scroll(function() { if($(window).scrollTop()+$(window).height()>=$(document).height()) fn() });