No Code Attached Yet Information Required
avatar ghazal
ghazal
30 Nov 2021

When using Web Assets basic method like this:

$wa = Factory::getApplication()->getDocument()->getWebAssetManager();
$wa->registerScript('bar', 'com_example/bar.js', [], ['defer' => true], ['core']);
// And use it later
$wa->useScript('bar');

I noticed that I couldn't really control the position of js scripts (or css files) in the listing deployed in head when displaying page.
Sometimes, it could be necessary, eg when I want my css file to load AFTER template.min.css

With HTMLHelper, js scripts and css files are (almost) always positioned by the end of the listing, as I wish.

HTMLHelper::_('script', ...

or

HTMLHelper::_('stylesheet',...

Do I miss something somewhere ?

Other question, related:
Is it mandatory to create a joomla.asset.json file in media/myfiles when I just want to add some js or css to an existing extension?

avatar ghazal ghazal - open - 30 Nov 2021
avatar ghazal ghazal - change - 30 Nov 2021
Labels Removed: ?
avatar joomla-cms-bot joomla-cms-bot - change - 30 Nov 2021
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 30 Nov 2021
avatar brianteeman
brianteeman - comment - 30 Nov 2021

I think you need to declare the dependencies

Is it mandatory to create a joomla.asset.json

No. Not if you registerScript in your code. If you do then you can just usescript

avatar Quy Quy - change - 9 Feb 2022
Labels Added: Information Required
avatar Quy Quy - labeled - 9 Feb 2022

Add a Comment

Login with GitHub to post a comment