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 ?
-
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.kemiller2002– kemiller20022012-05-15 12:03:00 +00:00Commented May 15, 2012 at 12:03
-
The loading is very slowly for me :(why– why2012-05-15 12:12:29 +00:00Commented 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.kemiller2002– kemiller20022012-05-15 12:14:01 +00:00Commented May 15, 2012 at 12:14
Add a comment
|
3 Answers
.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.');
});
Comments
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.