We can take the help of fetch, async and await javascript inbuilt features to hit the same url if it succeed. Using below script if user want to hit the url after first call completion he can do so easily. I have added for loop that will make 1400 times fetch request one by one. Its main benefit is you have not to worry async operation that may increase load due to multiple request in the same time. I mainly use this kind of script if I am supposing to scrap the content of other website that contains 40k plus pages.

<script>   
  async function myAsyncFunction() {
    try {
      var url =  "http://localhost/scrap_page_content.php";
      for (let index = 1; index <= 1400; index++) {
          console.log('starting'+index+'<br />');
          let awaitvar = await fetch(url);;
          // logs after one second
          console.log("data"+index, awaitvar);
      }
    } catch (ex) {
      return ex;
    }
  }
  myAsyncFunction();
  </script>

Leave a comment