user3093095
user3093095

Reputation: 71

JavaScript load faster?

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script>
        var siteTitle = $.ajax({
          url: 'http/',
          type: 'POST',
          data: { http: 'siteTitle' },
          success: function(title) {
            $('.title').html(title);
          }
        });
</script>

I have a site title and it's grabbed through jQuery's $.ajax() call. The title of the site needs to be configurable. So I grab the title through the ajax request but it doesn't show up on the site for about ~1.5s.

Is there anyway to decrease this time?

The site title is in about 6 places so it looks awkward with nothing there for ~1.5s.

Thanks.

Upvotes: 2

Views: 231

Answers (2)

jasonscript
jasonscript

Reputation: 6170

Have some default text like "loading..." as your title value. Then it won't be so bad when the ajax call updates it 1-2 seconds later.

If it is a span element (instead of a window title) then maybe even a loading gif. I think users are getting used to seeing those spinners now and won't question the extra 1-2 seconds wait time for the actual title

Upvotes: 0

TGH
TGH

Reputation: 39248

I would recommend that you handle the configurable title on the server and render it with the page instead of requesting it through ajax. Not sure what server side language you're using, but most will have a way to generate dynamic content on the server and pass it back to the browser.

Upvotes: 6

Related Questions