Feature #91951
openFLUID assets
0%
Description
Hello,
can we get a "order" attribute of the assets viewhelpers?
for example, I have 2 times the f:asset.script viewhelper in my template. The first one should be an inline script and the second one is an external file.
TYPO3 renders the external file before the inline one...
<f:asset.script identifier="first" priority="true">alert("my inline script");</f:asset.script>
<f:asset.script identifier="functions" src="EXT:my_ext/Resources/Public/JavaScript/functions.min.js" priority="true" />
Maybe you can change the "identifier" to get a sort order.
thank you!
Updated by Benni Mack about 3 years ago
- Status changed from New to Needs Feedback
Hello Christian,
do you want to get the inline code BEFORE the included external file?
Updated by Christian Hackl about 3 years ago
Benni Mack wrote in #note-2:
Hello Christian,
do you want to get the inline code BEFORE the included external file?
for this example yes, but not only for inline-code.
Updated by Garvin Hicking 3 months ago
Wouldn't maybe using "defer" for the external script solve this? Then the inline javascript would get parsed first.
Personally I don't think adding an order to javascripts is a solution that should be recommended (even though I understand the need).
Nowadays I would rather like to recommend building isolated javascript files that have no influence/dependency on each other. If they do, they should IMO be bundled, possibly by independent tooling (webpack, vite, etc.). What do you think?
Updated by Christian Hackl 3 months ago
@Garvin Hicking
hmm, I'm a fan of simple things, which doesn't exactly include all those package managers like webpack. :)
It would also be easier for beginners to understand, I would think ;)
Besides, I think it's possible in TypoScript, so why not in FLUID?
I don't know exactly how the FLUID is assembled at this point, if all the scripts / src'es are in an array before the HTML rendering, it shouldn't be a big problem to run a ksort() via the “identifier”. Maybe an additional TypoScript option / flag to switch the sorting on and off?
Updated by Garvin Hicking 3 months ago
Fair enough :)
I haven't checked in on how TS vs. fluid handles prioritization. Since it hasn't gained traction to get addressed in 4 years I'm not sure we will find someone to look into it, so I just wanted to offer an alternative other than "waiting for godot". ;)