is it possible to use the addScript with async="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');

1 Answer 1


If you have a look at the Joomla addScript 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);

The false is for $defer and true is for $async

  • - sorry just mistyped
    – webchun
    Commented Aug 31, 2015 at 3:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.