Skip to content

Commit ffad4af

Browse files
Add defer attribute to script tag
1 parent 6680c86 commit ffad4af

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

meta/tags.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ script:
4646
default: "'text/javascript'"
4747
type: "str | None"
4848
src: The location from which to load the script. If present, this will be used rather than the contents of the element.
49+
defer:
50+
doc: Defers execution of the script until the page has fully loaded.
51+
type: "bool | None"
4952

5053
style:
5154
escape_children: false

pyhtml/__tags/generated.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4116,6 +4116,7 @@ class script(Tag):
41164116
41174117
* `type`: Type of script to use (defaults to `'text/javascript'`)
41184118
* `src`: The location from which to load the script. If present, this will be used rather than the contents of the element.
4119+
* `defer`: Defers execution of the script until the page has fully loaded.
41194120
41204121
[View full documentation](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script)
41214122
"""
@@ -4124,19 +4125,22 @@ def __init__(
41244125
*children: ChildrenType,
41254126
type: str | None = None,
41264127
src: AttributeType = None,
4128+
defer: bool | None = None,
41274129
**attributes: AttributeType,
41284130
) -> None:
41294131
"""
41304132
Used to embed executable code or data; this is typically used to embed or refer to JavaScript code. The `<script>` element can also be used with other languages, such as [WebGL](https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API)'s GLSL shader programming language and [JSON](/en-US/docs/Glossary/JSON).
41314133
41324134
* `type`: Type of script to use (defaults to `'text/javascript'`)
41334135
* `src`: The location from which to load the script. If present, this will be used rather than the contents of the element.
4136+
* `defer`: Defers execution of the script until the page has fully loaded.
41344137
41354138
[View full documentation](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script)
41364139
"""
41374140
attributes |= {
41384141
'type': type,
41394142
'src': src,
4143+
'defer': defer,
41404144
}
41414145
super().__init__(*children, **attributes)
41424146

@@ -4145,24 +4149,27 @@ def __call__( # type: ignore
41454149
*children: ChildrenType,
41464150
type: str | None = None,
41474151
src: AttributeType = None,
4152+
defer: bool | None = None,
41484153
**attributes: AttributeType,
41494154
):
41504155
"""
41514156
Used to embed executable code or data; this is typically used to embed or refer to JavaScript code. The `<script>` element can also be used with other languages, such as [WebGL](https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API)'s GLSL shader programming language and [JSON](/en-US/docs/Glossary/JSON).
41524157
41534158
* `type`: Type of script to use (defaults to `'text/javascript'`)
41544159
* `src`: The location from which to load the script. If present, this will be used rather than the contents of the element.
4160+
* `defer`: Defers execution of the script until the page has fully loaded.
41554161
41564162
[View full documentation](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script)
41574163
"""
41584164
attributes |= {
41594165
'type': type,
41604166
'src': src,
4167+
'defer': defer,
41614168
}
41624169
return super().__call__(*children, **attributes)
41634170

41644171
def _get_default_attributes(self, given: dict[str, AttributeType]) -> dict[str, AttributeType]:
4165-
return {'type': 'text/javascript', 'src': None}
4172+
return {'type': 'text/javascript', 'src': None, 'defer': None}
41664173

41674174

41684175
def _escape_children(self) -> bool:

0 commit comments

Comments
 (0)