Why the Exam Timer Has to Live on the Server
Any timer kept in the browser can be tampered with. But polling the server every second isn't the answer either.
If the remaining time on an exam is held by JavaScript in the browser, anyone who opens the browser console can change it.
The right architecture
- When the candidate starts the exam, the server records the start time.
- The deadline is computed from that start time and the exam duration.
- The browser only displays the countdown; the number on screen carries no authority.
- When answers are submitted, the server checks again that the deadline hasn't passed.
Step 4 is the most important. If the server doesn't check at submission time, all the previous steps are decorative.
Why not ask the server every second
It's tempting to have the browser fetch the time from the server every second. But that means 100 simultaneous candidates generate 100 requests per second just for the timer — pointless load.
The right approach: sync once at the start, count locally after that, and re-sync on every real interaction (moving to the next question, saving an answer). That way the drift never gets large.
Don't trust the user's system clock
The local countdown must not use Date.now(), because the system clock can be set back. Use the browser's monotonic clock (performance.now()) instead, which counts from the moment the page opened and has nothing to do with the system clock.
When the internet drops
This scenario is common in Iran, and you should have decided on it in advance:
- Answers have to be saved as they are given, not only at the end — otherwise a disconnection means losing everything.
- If the candidate comes back and the deadline hasn't passed, they should be able to continue. The server knows where they were.
- If the deadline expires during the outage, the exam closes with the answers already saved.
The policy that "an internet outage is not a valid excuse" has to be announced before the exam; otherwise an appeal afterward is the candidate's right.
Extra time for special cases
Some candidates (for example, those with low vision) are legally entitled to extra time. This has to be adjustable at the level of the individual attempt, not the whole exam — and it should be logged who received extra time and why.