Just reading the HVUT's `$ajax` part of the code, the `$ajax.next()` implementation got my attentions:
CODE
next: function () {
if (!$ajax.queue[$ajax.index] || $ajax.error) {
return;
}
if ($ajax.tid) {
if (!$ajax.conn) {
clearTimeout($ajax.tid);
$ajax.timer();
$ajax.send();
}
} else {
if ($ajax.conn < $ajax.max) {
$ajax.timer();
$ajax.send();
}
}
},
This part doesn't feel right to me:
CODE
if (!$ajax.queue[$ajax.index] || $ajax.error) {
return;
}
if ($ajax.tid) {
if (!$ajax.conn) {
These three conditions can only be met when:
0. There are pending tasks waiting in the queue, the queue is not empty
1. The timer id is set, a.k.a. there was a previous `$ajax.next()` call that invoked `$ajax.timer()`. This means there is another `$ajax.next()` that is waiting to happen in the future.
2. There is no active running task. A.k.a. that previous request was actually the last batch of the tasks.
But how can this current `$ajax.next()` call happen when there is no active running task, while there are pending tasks in the queue?
The only possible reason would be that this current `$ajax.next()` call is either triggered by `$ajax.add()` (user action adding new tasks) or `$ajax.onload()`/`$ajax.onerror()`. In anyway, HVUT would immediately `clearTimeout` and begin new request. Thus, there won't be enough wait between last request and this request.
This edge case is very hard to trigger and is most likely not to trigger any rate limit. But ideally, `$ajax.next()` should do nothing and early return if `$ajax.tid`is already set, thus waiting for the that already scheduled `$ajax.next()`, to ensure every `$ajax.send()` is spaced by 300ms.
This post has been edited by OnceForAll: Oct 21 2025, 15:36