Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Related to #1140356: Add async, onload property to script tags.
These lines from common.inc...
<?php // Element properties that do not depend on item type.
$element = $element_defaults;
if (!empty($item['defer'])) {
$element['#attributes']['defer'] = 'defer';
}
?>
...Are in direct conflict with this draft HTML 5 spec:
The defer and async attributes must not be specified if the src attribute is not present.
Comment | File | Size | Author |
---|---|---|---|
#10 | d7-script_defer_to_spec-1503804-10.patch | 1.95 KB | iamEAP |
#9 | d7-script_defer_to_spec-1503804-9.patch | 1.95 KB | iamEAP |
#4 | d8-script_defer_to_spec-1503804-4.patch | 968 bytes | iamEAP |
#1 | core-script_defer_to_spec-1503804-1.patch | 1.37 KB | iamEAP |
Comments
Comment #1
iamEAP CreditAttribution: iamEAP commentedPreliminary patch that takes care of this.
Also tagged html5.
Comment #2
arnested CreditAttribution: arnested commentedYes, 'defer' should only be added to file and external and the patch works fine.
Comment #3
nod_how about unset-ing #attributes['defer'] in inline scripts? that would avoid some duplication.
Comment #4
iamEAP CreditAttribution: iamEAP commentedHow about if we move it after the switch/case block? We can check for an src attribute and line up directly with the spec definition.
Comment #5
iamEAP CreditAttribution: iamEAP commentedI might say this needs backporting too. Tagging.
Comment #6
arnested CreditAttribution: arnested at Reload commentedYes, much better approach in #4.
Reviewed and tested. Works like a charm.
Comment #7
Dries CreditAttribution: Dries commentedCommitted to 8.x. Moving to 7.x.
Comment #8
iamEAP CreditAttribution: iamEAP commentedComment #9
iamEAP CreditAttribution: iamEAP commentedGoing ahead and reducing redundancy in D7.
Comment #10
iamEAP CreditAttribution: iamEAP commentedSame, but doesn't wipe unrelated comments.
Comment #11
ericduran CreditAttribution: ericduran commentedFor D7, I think is best to just mark this issue as closed and instead fix defer and async in one shot over at #1140356: Add async, onload property to script tags. The other patch fixes this issue and also adds test.
Comment #12
tim.plunkettFixing tag.
Comment #14
ericduran CreditAttribution: ericduran commentedI think this should just be marked as dupe but I'll leave it to someone else.
#1140356: Add async, onload property to script tags already got in to D8, which is a better fixed (on top of this D8 patch) for this problem and that one is also marked for backport. But 1st #1587536: JavaScript aggregation should account for "async" and "defer" attributes needs to be fixed.
So I don't think this issue is needed.
Comment #15
iamEAP CreditAttribution: iamEAP commentedYeah, there are some pros and cons to that.
On the one hand, the two (three) issues are very tightly knit and a backport for #1140356: Add async, onload property to script tags would depend on this.
On the other hand, this is still a separate bug with an easy fix. It's likely the aforementioned issue (along with #1587536: JavaScript aggregation should account for "async" and "defer" attributes will probably stay active for at least another month. No use in having this similar but distinct bug remain a bug while a new feature is added and backported.