5

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

1

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.

Example:

$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

0

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

How can I insert js scripts before </body>

0

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 you have read our privacy policy.

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