Hi,
I'm using the Web Asset Manager to replace the old "addScript" method. The problem is that the WA does not render the file url correctly in call cases.
Tested with the function:
$wa = \Joomla\CMS\Factory::getApplication()->getDocument()->getWebAssetManager();
$wa->registerAndUseScript($name, $url ...)
Url used : /media/com_test/assets/script.js
Expected result (working with addScript) : <script src="/media/com_test/assets/script.js ...
Real result : <script src="//media/com_test/assets/script.js ...
there is an additional slash at the start of the file
If I use a variable in the url, then it works
Url used : /media/com_test/assets/script.js?rev=123
Real result : <script src="/media/com_test/assets/script.js?ver=123 ...
there is no additional slash
This problem occours when you are working in a subfolder and using the multilanguage
Page url : http://localhost/joomlatest/index.php/fr/
Url used : /joomlatest/media/com_test/assets/script.js
Expected result (working with addScript) : <script src="/joomlatest/media/com_test/assets/script.js ...
Real result : <script src="/joomlatest/joomlatest/media/com_test/assets/script.js ...
the root is duplicated
why does the WA add some data to the url passed ? this must not be done. The url must be given by the variable passed to the function, and it must not be altered
| Labels |
Removed:
?
|
||
| Labels |
Added:
No Code Attached Yet
|
||
Build: 5.3.4 as stated in the report :)
It expecting relative path or URL.
Url used : /media/com_test/assets/script.js
This is not URL ;)
I think the code is expecting the path to be without leading slash.
It something with it
joomla-cms/libraries/src/HTML/HTMLHelper.php
Line 391 in b7fee10
I don't use the HTMLHelper, I use the $doc->addScript
the problem is that the way to work has changed.
something works with the $doc->addScript
the same DOES NOT work with the WebAssetManager
It's a fact and it's breaking things
It expecting relative path or URL.
Just do that, and all will work
of course I did not expect that you unerstand ... as always for more than 10 years, always the same situation.
You using WebAssetItem incorrectly, what I not understand?
the fact is that the code does not work as before
$doc->addScript has been replaced by the WebAssetManager. You can not use it in the same way and all the function calls that were working for years will be broken.
It is not 1:1 replacement.
$doc->addScript required URL or full path (relative to domain).
WebAssetManager requires URL or path relative to the site root, or relative to media folder.
Your code does not work because you use path relative to domain.
Make sure all your function calls use path relative to the site root then all will work.
I understand that
but it does not solve the problem of breaking things
@ced1870 Always a good idea when report an issue: Let us know on which Joomla version you have observed it.