How can I prevent my javascript from polling websites too fast? -


I created this website some time ago for the purpose of grabbing and displaying random puu.sh images. This is also a warning, the content that is generated by this site is generated, and I can not guarantee it to SFW.

I have started to look at it again, and it seems that there is something in it with serious bugs with the system used to collect the content How can I change so that he can not spam puu.sh and refuse to accept it?

Here is the code:

  var currentThumb = 0; Function getImgUrl () {var text = (Math. (Math.rendum (* 9)) ToString (); // var text = '3T'; var possible = "ABCDEFGHIKLMAPQRTUVXXBCCDGGLMNAPQRSUVXX123456789" (var i = 0 ; I & lt; 4; i ++) text + = possible.Chat (Math. Floor (Math.Random) * Possible length); Return 'http://puu.sh/' + Text;} Function Open_in_new_tab (url) {var win = window.open (url, '_blank'); win.focus ();} function getImages () {// var width = window.innerWidth; Var for picture = 10; var var = 0; i & lt; image; i ++) {var url = getImgUrl (); Document.getElementBy Id ('thumb'). InnerHTML + ''   

The problem is most likely

  $ ('img'). Error (function () {$ (this) .attr ('src', getImgUrl ()); setBig ();});  

Your main problem is that you are spamming the server when you are 404 Try something like error (function () {var _this = this; setTimeout (function () {$ (_ this) .attr ('src', getImgUrl ()) due to the error handler

  $ ('img').)); Setgig ();}, 500); // whatever timeout is not good for not spam)};    

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -