0

I'm building a prize competitions website and have a question regarding multiple setIntervals.

I currently have the following on the home page:

enter image description here

Four products showing a countdown timer of when the competition will end.

I have a page named "Competitions" that lists all active competitions and it's paginated so shows 8 competitions per page.

Would there be any performance issues if I were to have a timer for every single product? This could easily be hundreds of products.

Just to add, the way I have done this is to create an array named timer and then push each countdown timer into it. Currently that array only holds 4 countdown timers.

Just want to know how scalable this is.

Dally
  • 1,281
  • 4
  • 18
  • 37
  • why dont you have 1 timer for every produc? – bill.gates Jun 30 '20 at 09:33
  • What about having one interval, which updates all products? For example you have one product which will expire in 5 days and one which will expire in 2 days. On `setInterval` you just update both variables that hold "time left" for the products. This way you'll need only one interval for any number of products. And they won't ever desync for some reason. – Vladimir Bogomolov Jun 30 '20 at 09:35
  • Using your example @VladimirBogomolov, if I had one setInterval for 300 products, would that cause any kind of performance issues for the client? – Dally Jun 30 '20 at 09:55
  • 1
    I don't think it would, also you can read this https://stackoverflow.com/questions/2553138/how-many-javascript-settimeout-setinterval-call-can-be-set-simultaneously-in-on – Vladimir Bogomolov Jun 30 '20 at 10:03
  • This will scale just fine, at least up to the number of products that is still useful to display on one page at once. – Bergi Jun 30 '20 at 11:06

0 Answers0