arvgta / ajaxify

Ajaxify - The Ajax Plugin
https://4nf.org/
274 stars 124 forks source link

My first semaphore... #178

Closed arvgta closed 4 years ago

arvgta commented 4 years ago

...in a JavaScript environment.

This is the issue of "Edin's ideas" which I would like to tackle first.


Original reporting of the bug:

There is no need to prefetch page if link is already clicked anyway.


The bug was reproduced on several sites including:

arvgta commented 4 years ago

This is a subset of this larger issue and was solved during this commit by enabling a new semaphore mechanism, which prevents thrashing on the same URL..

Because enabling the semaphore was placed in the common _request() handler, in addition to normal click requests, GET and POST of form requests are also locked....


New code

In the (common) _request() handler, the following code enables the semaphore:

$.rq("!"); //we're serious about this request - disable further fetches on same URL

In the $.rq() sub-plugin, the following changes were made (second constraint of the OR condition):

if(o === "=") { 
    return h === currentURL //check whether internally stored "href" ("h") variable is the same as the global currentURL
    || h === l; //or href of last request ("l") //this constraint is new
}

...and...

if(o === "!") return l = h; //store href in "l" (last request)
arvgta commented 4 years ago

Tested to work fine... Thus closing... If you have any funnies, please re-open

edito commented 4 years ago

Just to mention that current semaphore, altogether with f876773 fix, covers only Option 2 -> Situation 1 from #179 issue, which caused most of the refreshes. While Option 1 and Option 2 -> Situation 2 are not covered yet.

In case of partner site, where refresh is set to false, the only thing that causes periodic refresh is Option 2 -> Situation 2 from #179.