2
<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.

18
  • So what exactly takes those 1.5s to perform? Commented Feb 20, 2014 at 4:39
  • 2
    You cant do much to decrease the time, it depends on the internet connection, server (backend) execution speed and few other factors. You have to optimize the server side code. Commented Feb 20, 2014 at 4:42
  • 1
    @Graham Walters: it's really a good chance jQuery is already in the user's cache. If it's not - it will be loaded just once Commented Feb 20, 2014 at 4:47
  • 1
    @user3093095 - You are using AJAX for the sites title. Just get the server to deliver the right content in the first place. Use AJAX for interactivity. Commented Feb 20, 2014 at 4:48
  • 1
    @user3093095 - You download the jquery.min.js and save it your local project path and then refer the js to your HTML file. It will run faster and better. Commented Feb 20, 2014 at 5:04

2 Answers 2

6

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.