0

I calling multiple function on page load in my asp.net web application.

All function run on page ready method see the below code

 $(document).ready(function(){
     func1();
     func2();
     func3();
    //....  so on.
    });
    function func1()
    {
    $.ajax({
     type: "POST",
      url: "Contents.asmx/GetText",
      data: "{ }",
      contentType: "application/json; charset=utf-8",
      dataType: "json",
      success: function (msg) {
            /some code
      }
    });
    }

    function func2()
    {
    $.ajax({
     type: "POST",
      url: "Contents.asmx/GetTitles",
      data: "{ }",
      contentType: "application/json; charset=utf-8",
      dataType: "json",
      success: function (msg) {
            /some code
      }
    });
    }

.... like wise others

For backend I using SQL server-05. When page is loading It getting more time to load, above functions takes 30+ seconds to load.

How to optimze function calling?..

11
  • 2
    So where do you think the delay is? In your javascript, the server or the SQL server? Commented Jun 10, 2011 at 11:08
  • 2
    Well, try optimizing your queries. Maybe even use caching to avoid hitting the DB server all the time if those queries are expensive. Commented Jun 10, 2011 at 11:09
  • In javascript. All method call some of SQL functions at a time. so the issues comes. Commented Jun 10, 2011 at 11:09
  • @Darin you say that I need optimize SQL queries.. right. Commented Jun 10, 2011 at 11:10
  • any other way to optimize Javascript calling. If there is no issues in SQL Query. then ?? Commented Jun 10, 2011 at 11:11

2 Answers 2

1

You could aggregate all the queries into a new web method which will perform all the SQL queries at once. Then send a single AJAX request to this new method. And as far as your SQL server is concerned you could also send multiple SQL queries into a single round-trip. Try optimizing the SQL queries as much as possible. Also you could cache the results of some expensive queries.

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

2 Comments

@Abhishek, what have you tried? What issues are you encountering?
I checking Stored procedures but in my local PC it working fine on live server it getting more time to execute...
1

As long as /some code is not too much there is not really much you can do. These ajax calls area light-weight. Your problem is probably in the backend, where you send your requests to.

To debug/profile your problem, first check your ajax requests. Check them in a web-tool like Firebug and see that your request is expected. There you can also check which of your requests takes how long.

As you now see your bottleneck (e.g. requesting Contents.asmx/GetTitles is what takes so long), check your server that provides that page. As you did not provide code of that one, we can not help you there. But that’s where you have to look for next.

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.