Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Position of js scripts or css files in head using Web Assets method ? #36167

Closed
ghazal opened this issue Nov 30, 2021 · 1 comment
Closed

Position of js scripts or css files in head using Web Assets method ? #36167

ghazal opened this issue Nov 30, 2021 · 1 comment

Comments

@ghazal
Copy link
Contributor

ghazal commented Nov 30, 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?

@brianteeman
Copy link
Contributor

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

@joomla joomla locked and limited conversation to collaborators Feb 9, 2022
@Quy Quy converted this issue into discussion #36984 Feb 9, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Projects
None yet
Development

No branches or pull requests

4 participants