I'm using $doc->addScript($path.'/js/script.js'); to load a Javascript file inside the head section. Is there any native way to load it in the bottom of the page, before the closing </body> tag? Thanks!

3 Answers 3


No there isn't.

addScript(string $url, string $type = "text/javascript", boolean $defer = false, boolean $async = false)

You can use $defer and $async parameters of the addScript method to load JavaScript after the content.


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

Use $defer = true if you want to load scripts in order, i.e. if one script is dependant on another.

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

Use $async = true to load scripts asynchronously and when the order in which they are loaded does not matter


If you've just landed here via google see answer to this question here:

How can I insert js scripts before </body>


Look for a plugin called "ScriptsDown" in the JED

Your Answer

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

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