if you add a js file using :
JFactory::getDocument()->addScriptDeclaration('
// some code
');
OR
$document = JFactory::getDocument();
$document->addScript('PATH_TO_SCIPRT');
will be automatically added in the head of the document
In the arguments of addScript add a head:Boolean, true => put it int the by default, false put it before </body>
Always in the head
Title |
|
Btw, if you want to load JS files, you can use async and defer tags to tell the browser that he can safely load the script later or parallel and doesn't have to stop rendering the page.
See https://api.joomla.org/cms-3/classes/JDocument.html#method_addScript
Yeah sure, but nothing in google,
Also I want to load it after loading of the page, a great way for optimization, if I'm working on webapp, and I have a lot of JS files, they will block my pages.
Also for other CMS like wordpress you can specify when you put your script : http://codex.wordpress.org/Function_Reference/wp_enqueue_script ;)
In the arguments of addScript add a head:Boolean, true => put it int the by default, false put it before
</body>
why this is expected, when addScript
do not support such thing, in which documentation you found it?
Also I want to load it after loading of the page, a great way for optimization, if I'm working on webapp, and I have a lot of JS files, they will block my pages.
The defer and async flags will not block your pages. They are exactly for that use case. Async means that the browser can load the file whenever he wants, in any order. Defer means he can load them after the page is loaded, but in order.
Actually, deferring and asynchronous loading of JS files is better than using the hackish trick to put them at the end of the page. All modern browsers support those flags. Basically only IE9 doesn't support it afaik, and for that browser it will just be a slower page.
I used already Async, butt always wa have a problem some js files depend on others ;)
If they depend on other files, you should use defer and not async. Because defer will load them in order (after the page is loaded).
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2014-12-16 15:46:01 |
Labels |
Added:
?
|
Are you referring to the "google" way of putting a script call just before the closing body tag?
That is indeed not possible with the current API.
Or why do you need to call it at this place?