Skip to content
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

Async/defer attributes implemented incorrectly #1870

Open
abvdveen opened this issue Aug 2, 2023 · 2 comments
Open

Async/defer attributes implemented incorrectly #1870

abvdveen opened this issue Aug 2, 2023 · 2 comments

Comments

@abvdveen
Copy link

abvdveen commented Aug 2, 2023

Async and defer attributes now can only be added when also adding standalone="true". This doesn't work: using standalone="true" will generate inline js. Adding defer="defer" or async="async" to inline js is useless, as there is nothing to fetch. These params influence when external js is fetched, so only works when the 'src' param is present in the script tag.

Changing AssetService as follows fixes this:

if ($extractedAssetSettings['standalone']) {
    $assetSettings = $extractedAssetSettings;
}

to

$assetSettings = $extractedAssetSettings;

and

               if ($standaloneAssetSettings) { 
                 // using async and defer simultaneously does not make sense technically, but do not enforce 
                 if ($standaloneAssetSettings['async']) {
                    $tagBuilder->addAttribute('async', 'async');
                 }
                 if ($standaloneAssetSettings['defer']) {
                    $tagBuilder->addAttribute('defer', 'defer'); 
                 }
               }

to

                 // using async and defer simultaneously does not make sense technically, but do not enforce
                 if ($standaloneAssetSettings['async']) {
                  $tagBuilder->addAttribute('async', 'async');
                 }
                 if ($standaloneAssetSettings['defer']) {
                   $tagBuilder->addAttribute('defer', 'defer');
                 }
@NamelessCoder
Copy link
Member

standalone="1" plus external="1" should work for you. Standalone asset settings must only be applied if an asset is standalone, otherwise it would also potentially apply to a merged chunk of assets leading to unpredictable results.

@abvdveen
Copy link
Author

abvdveen commented Aug 7, 2023

Unfortunately I cannot use that combination in this case: I need to generate the contents of the <v:asset.script> tag in a Fluid file, based on parameters for the current page.
So I have xclassed the AssetService for this particular project, to get the desired result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants