10

is it possible to use theaddScript withasync="true"?

I found a hack that uses some clever quoting to trick the embed function, but it seems as if this could be a native feature:

$doc->addScript("//myscript.js", 'text/javascript" async="true');
Valentin Despa's user avatar
Valentin Despa
3,6502 gold badges22 silver badges42 bronze badges
askedAug 13, 2014 at 16:46
user101289's user avatar

1 Answer1

11

If you have a look at the JoomlaaddScript function, it shows the following:

public function addScript($url, $type = "text/javascript", $defer = false, $async = false){    $this->_scripts[$url]['mime'] = $type;    $this->_scripts[$url]['defer'] = $defer;    $this->_scripts[$url]['async'] = $async;    return $this;}

$async is a boolean therefore the following should work for you:

$doc->addScript('//myscript.js', 'text/javascript', false, true);

Thefalse is for$defer andtrue is for$async

answeredAug 13, 2014 at 17:17
Lodder's user avatar
1
  • - sorry just mistypedCommentedAug 31, 2015 at 3:38

Your Answer

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy 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.