You also probably have a helper method in your base library, for example in jQuery, jQuery.now() wraps (new Date()).getTime()
-----Original Message----- From: jsmentors@googlegroups.com [mailto:jsment...@googlegroups.com] On Behalf Of Ben Barber Sent: Monday, December 20, 2010 12:23 PM To: jsmentors@googlegroups.com Subject: Re: [JSMentors] Image polling through Javascript I'm a fan of using implicit number conversion on Dates using the unary '+' operator (http://xkr.us/articles/javascript/unary-add/). "http://....gif?" + ( +new Date() ); Ben Barber On Mon, 20 Dec 2010 04:44:44 -0600, Amit Agarwal <lifea...@gmail.com> wrote: > yeah, I liked the timestamp concept. > > Modified my code and worked perfectly :) > > Thanks! > > -Regards > *Amit Agarwal <http:///www.amitagrwal.com>* > +91-779-822-8765 > > > > On Mon, Dec 20, 2010 at 3:35 PM, Shane Tomlinson <set...@gmail.com> > wrote: > >> I personally like to use timestamps over ints or rand, a timestamp is >> ensured to be unique. If you use an int and in this session you had >> "http://.....gif?1", the next time the user goes into the app, they >> re-use the integer 1, using the cache. And Math.random isn't as >> random as you want it to be: >> http://stackoverflow.com/questions/1062902/how-random-is-javascripts-math-random. >> But a timestamp, that is going to be unique unless you reset your >> system's clock. >> >> And performance wise, trying to optimize this is a >> premature-optimization. >> Unless your request is called many many thousands of times a second, >> the performance overhead of using a timestamp will be effectively 0. >> >> Check out: >> https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/ >> Date/getTime, this returns the number of milliseconds since Jan 1, >> 1970, again, unless the user resets their system clock, it is >> guaranteed to be unique. >> >> try requesting: "http://....gif?" + ( new Date() ).getTime(); >> >> >> On Mon, Dec 20, 2010 at 9:45 AM, Loic Giraudel >> <l.girau...@gmail.com>wrote: >> >>> Or for better performance a simple incremented int variable. >>> >>> >>> On Mon, Dec 20, 2010 at 10:43, fernando trasvina >>> <trasv...@gmail.com>wrote: >>> >>>> use ?Math.random() on ur uri >>>> or timestamp + Math.random() >>>> >>>> On Dec 20, 2010, at 3:35 AM, Amit Agarwal wrote: >>>> >>>> Hi every one, >>>> >>>> I need to poll an image using javascript and need to perform an >>>> action once the image is found at its position. This is the code I >>>> have written for this task. >>>> >>>> /*----Image handling script starts here----*/ var beacon = new >>>> Image(); >>>> >>>> >>>> >>>> >>>> >>>> beacon.onload = function() { >>>> >>>> >>>> console.log('Image found'); >>>> console.log(this.width,this.height); >>>> >>>> >>>> >>>> >>>> >>>> window.clearInterval(timer); >>>> }; >>>> >>>> >>>> beacon.onerror = function(){ >>>> console.log('Image not found'); >>>> >>>> >>>> >>>> >>>> } >>>> var timer = window.setInterval(function(){ >>>> >>>> >>>> console.log('sending the request again'); >>>> beacon.src = >>>> "http://www.google.co.in/logos/2010/lennon10-hp.gif"; >>>> >>>> >>>> >>>> >>>> },2000); >>>> /*----Image handling script ends here----*/ >>>> >>>> Problem is that, after one GET request, the response gets cached >>>> and requests don't get sent everytime I set src. If you examine NET >>>> tab, it sends request only on first src set and caches the >>>> response. >>>> >>>> I need to send a fresh request for image every time my code sets >>>> the src. >>>> Any workarounds? >>>> >>>> -Regards >>>> *Amit Agarwal <http:/www.amitagrwal.com>* >>>> +91-779-822-8765 >>>> >>>> >>>> -- >>>> To view archived discussions from the original JSMentors Mailman list: >>>> http://www.mail-archive.com/jsmentors@jsmentors.com/ >>>> >>>> To search via a non-Google archive, visit here: >>>> http://www.mail-archive.com/jsmentors@googlegroups.com/ >>>> >>>> To unsubscribe from this group, send email to >>>> jsmentors+unsubscr...@googlegroups.com >>>> >>>> >>>> -- >>>> To view archived discussions from the original JSMentors Mailman list: >>>> http://www.mail-archive.com/jsmentors@jsmentors.com/ >>>> >>>> To search via a non-Google archive, visit here: >>>> http://www.mail-archive.com/jsmentors@googlegroups.com/ >>>> >>>> To unsubscribe from this group, send email to >>>> jsmentors+unsubscr...@googlegroups.com<jsmentors%2bunsubscr...@goog >>>> jsmentors+legroups.com> >>>> >>> >>> -- >>> To view archived discussions from the original JSMentors Mailman list: >>> http://www.mail-archive.com/jsmentors@jsmentors.com/ >>> >>> To search via a non-Google archive, visit here: >>> http://www.mail-archive.com/jsmentors@googlegroups.com/ >>> >>> To unsubscribe from this group, send email to >>> jsmentors+unsubscr...@googlegroups.com<jsmentors%2bunsubscr...@googl >>> jsmentors+egroups.com> >>> >> >> -- >> To view archived discussions from the original JSMentors Mailman list: >> http://www.mail-archive.com/jsmentors@jsmentors.com/ >> >> To search via a non-Google archive, visit here: >> http://www.mail-archive.com/jsmentors@googlegroups.com/ >> >> To unsubscribe from this group, send email to >> jsmentors+unsubscr...@googlegroups.com<jsmentors%2bunsubscr...@google >> jsmentors+groups.com> >> -- To view archived discussions from the original JSMentors Mailman list: http://www.mail-archive.com/jsmentors@jsmentors.com/ To search via a non-Google archive, visit here: http://www.mail-archive.com/jsmentors@googlegroups.com/ To unsubscribe from this group, send email to jsmentors+unsubscr...@googlegroups.com -- To view archived discussions from the original JSMentors Mailman list: http://www.mail-archive.com/jsmentors@jsmentors.com/ To search via a non-Google archive, visit here: http://www.mail-archive.com/jsmentors@googlegroups.com/ To unsubscribe from this group, send email to jsmentors+unsubscr...@googlegroups.com