N
N
Nikolay2015-10-03 23:04:50
PHP
Nikolay, 2015-10-03 23:04:50

How often should the form be checked?

There is one field where the user must enter the title and another field where the title is automatically translated into url format using slugify. So far, with each new character in the title field, a request is sent to the server where slugify works and it also checks whether there is such a url in the database, and returns a response with url and true / false depending on the presence in the database.
Also, the user can change it himself after with the url and again there will have to be checks.
I want to reduce the load on the server and make some kind of timeout, how often should a check be done in practice in such a situation, or maybe another principle is needed?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
WebDev, 2015-10-03
@MykolaPr

All of these methods are not suitable if when you click on the "save" button, you redirect to another page. The most correct option is to send a request not immediately after pressing the key, but after some time. Some kind of timer that resets if the user continues to enter text. Usually, such a method is called "debounce", and is already implemented in various libraries, for example, in underscrore.
If you don't want to include a library, you can write it yourself, something like this:

function debounce(method, timeout) {
        clearTimeout(method._tId);
        method._tId = setTimeout(function(){
            method();
        }, timeout);
    }       }, timeout);
}

We describe the required method:
function checkTitle() {
 //Код проверки
}

And we hang it on the event:
$('input').on('keyup', function() {
   debounce(checkTitle, 1000);
});

As a result, if a second has passed since the last character was entered and the user has not entered anything else, the checkTitle() method will be called.

M
Maxim E, 2015-10-03
@creativeworm

Translate to transliteration when sending a request to the server (by clicking on the "save" button), then check if it is busy and add "-2", "-3", etc. if it matches. if there is such a url or time.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question