Take the 2-minute tour ×
Joomla Stack Exchange is a question and answer site for Joomla! administrators, users, developers and designers. It's 100% free, no registration required.

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

1 Answer 1

up vote 6 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

Your Answer

 
discard

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.