Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript in Ajax loads very slowly

I have 2 pages, when the second page load in first page, the JavaScript of that pages run after all the JavaScript and load very slowly. I wrote the below code to show the spinner till the second page load completely. But the spinner doesn't s work. Here is my code:

<script>
    $('.tourajaxi').html('<i class="fa fa-spinner fa-pulse fa-3x fa-fw" ></i><span class="sr-only">Loading ...</span>');
     $(window).load(function()  {
    $('.tourajaxi').load('/toursajax.bc?gid=325');
    });
    </script>
like image 272
inaz Avatar asked Aug 28 '16 06:08

inaz


People also ask

Why ajax response is slow?

There are two different types of issues that can cause admin-ajax. php slow server responses. The first is a backend CPU issue and the second is more of a frontend issue where you will notice third party plugins polling this file in your website speed tests.

Are ajax calls slow?

In my app, there are a lot of ajax calls. A user may do 50 ajax calls per session, so speed is very important. The ajax call queries the database and returns a list of records.

Is ajax better than Javascript?

Javascript provides client-side support whereas AJAX provides server-side support by exchanging data with the server. Javascript is applicable when there is an HTML and AJAX functionality that takes data using XMLHttpRequest. Javascript is a well-known programming language whereas AJAX is not a programming language.


1 Answers

A guess, since you haven't included any HTML:

Your script is in the <head> of the document, and tries to apply HTML to the element "tourajaxi", but that element does not exist until the rest of the document is loaded.

like image 51
Kae Verens Avatar answered Oct 17 '22 08:10

Kae Verens