Difference between document.createElement ('script') vs jQuery.getScript

I am having a problem with what .getScriptworks in some odd cases.

For example, this works to load scripts only when necessary.

function twitterSDK() {
    $jQ.getScript('http://platform.twitter.com/widgets.js');
}

function diggShare() {
    $jQ.getScript('http://widgets.digg.com/buttons.js');
}

function buzzShare() {
    $jQ.getScript('http://www.google.com/buzz/api/button.js');
}

However, it does not seem to work on several scripts that I wrote. If I call .getScriptto extract this JS file that I uploaded to Pastebin ( http://pastebin.com/GVFcMJ4P ), but the call tweetStream();does not happen. However, if I do the following, this works:

var twitter = document.createElement('script');
twitter.type = 'text/javascript';
twitter.async = true;
twitter.src = '/path-to/tweet.js';
$jQ('.twitter-section').append(twitter);
tweetStream();

What am I doing wrong? Any help would be awesome, thanks!

PS Which method is faster or more efficient?

. pastebin, .js, , , . ;)

+3
1

jQuery $jQ.getScript() - . , tweetStream() getScript(), script.

tweetStream() ( ) .

$jQ.getScript('/path-to/tweet.js', function() {
    tweetStream();
});

, this tweetStream().

$jQ.getScript('/path-to/tweet.js', tweetStream);
+4

Source: https://habr.com/ru/post/1781134/


All Articles