1

There is one javascript file http://v2.jiathis.com/code_mini/jia.js, in order for good speed , I want to load it asynchronous, how to do this by jquery ?

3
  • The script isn't that large. You most likely don't need to load this async as it probably won't make that much of a difference. Commented May 15, 2012 at 12:03
  • The loading is very slowly for me :( Commented May 15, 2012 at 12:12
  • Are you hosting it locally? If not, I would try that and see if that improves the results. I can query the script with a sub second response. Commented May 15, 2012 at 12:14

3 Answers 3

4

.getScript() can help you the things Getscript: load a JavaScript file from the server using a GET HTTP request, then execute it.

The script is executed in the global context, so it can refer to other variables and use jQuery functions. Included scripts can have some impact on the current page

$.getScript("yourJavascriptUrl", function(data, textStatus, jqxhr) {
   console.log(data); //data returned
   console.log(textStatus); //success
   console.log(jqxhr.status); //200
   console.log('Load was performed.');
});
Sign up to request clarification or add additional context in comments.

Comments

1

use :

$.ajax({
  url: http://v2.jiathis.com/code_mini/jia.js,
  dataType: "script",
  success: success
});

or

getScript();

Comments

1

Have you tried with

$.ajax({
  type: "GET",
  url: "http://v2.jiathis.com/code_mini/jia.js",
  dataType: "script"
});

If html is specified, any embedded JavaScript inside the retrieved data is executed before the HTML is returned as a string. Similarly, script will execute the JavaScript that is pulled back from the server, then return nothing.

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.