Skip to content

Async/defer attributes implemented incorrectly #1870

Open
@abvdveen

Description

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');
                 }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions