I noticed a really weird behavior with my ajax calls. Every other ajax call always have a 300ms delay.
Here is what the network section look like. I looked at the details of the call. Here is the fast ajax call, and here is the slow ajax call.
The slow ajax call has 2 extra fields - DNS lookup and Initial Connection.
Why does this happen every other ajax call? How can I ensure consistent ajax performance?
The test code:
<body>
<input type="button" class="btn" id="testButton" value="Test"/>
</body>
<script>
document.getElementById('testButton').onclick = function() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
console.log('done');
}
};
xhttp.open("GET", "{% url 'test_ajax' %}", true);
xhttp.send();
}
</script>
def test_ajax(request):
return JsonResponse({'a': 'a'})
EDIT: I tried doing the ajax call with jQuery, still the same issue.