Is this a good approach to create countdown timer like this?

Posted 8 months ago by behnampmdg3


How would you tackle this issue:


When a visitor hits the page, load a countdown timer that shows X days, hours and minutes before expiring. When the visitor returns, the timer should be set from the time visitor first visited the page.

My solution:

Give a piece of Javascript code to the client to embed in the page. Each time that code gets loaded, I create a record with IP address of the visitor in the database.

When that page gets reloaded, I query the database, if the IP exists, instead of creating the record, I load the countdown timer associated with that id, calculate the time since created, and load the countdown accordingly.


Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.