Joomla Stack Exchange is a question and answer site for Joomla! administrators, users, developers and designers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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');
share|improve this question
up vote 8 down vote accepted

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

share|improve this answer
- sorry just mistyped – webchun Aug 31 '15 at 3:38

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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