You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: aspnetcore/blazor/javascript-interoperability/location-of-javascript.md
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,17 +33,17 @@ Load JavaScript (JS) code using any of the following approaches:
33
33
34
34
:::moniker-end
35
35
36
+
## Location of `<script>` tags
37
+
36
38
:::moniker range=">= aspnetcore-8.0"
37
39
38
-
> [!WARNING]
39
-
> Only place a `<script>` tag in a component file (`.razor`) if the component is guaranteed to adopt [static server-side rendering (static SSR)](xref:blazor/fundamentals/index#client-and-server-rendering-concepts) because the `<script>` tag can't be updated dynamically.
40
+
Only place a `<script>` tag in a component file (`.razor`) if the component is guaranteed to adopt [static server-side rendering (static SSR)](xref:blazor/fundamentals/index#client-and-server-rendering-concepts) because the `<script>` tag can't be updated dynamically. Placing a `<script>` tag in a component file doesn't produce a compile-time warning or error, but script loading behavior might not match your expectations in components that don't adopt static SSR when the component is rendered.
40
41
41
42
:::moniker-end
42
43
43
44
:::moniker range="< aspnetcore-8.0"
44
45
45
-
> [!WARNING]
46
-
> Don't place a `<script>` tag in a component file (`.razor`) because the `<script>` tag can't be updated dynamically.
46
+
Don't place a `<script>` tag in a component file (`.razor`) because the `<script>` tag can't be updated dynamically. Placing a `<script>` tag in a component file produces a compile-time error.
47
47
48
48
:::moniker-end
49
49
@@ -61,7 +61,7 @@ Load JavaScript (JS) code using any of the following approaches:
61
61
62
62
:::moniker-end
63
63
64
-
###Load a script in `<head>` markup
64
+
## Load a script in `<head>` markup
65
65
66
66
*The approach in this section isn't generally recommended.*
67
67
@@ -84,7 +84,7 @@ Loading JS from the `<head>` isn't the best approach for the following reasons:
84
84
* JS interop may fail if the script depends on Blazor. We recommend loading scripts using one of the other approaches, not via the `<head>` markup.
85
85
* The page may become interactive slower due to the time it takes to parse the JS in the script.
86
86
87
-
###Load a script in `<body>` markup
87
+
## Load a script in `<body>` markup
88
88
89
89
Place the JavaScript tags (`<script>...</script>`) inside the [closing `</body>` element](xref:blazor/project-structure#location-of-head-and-body-content) after the Blazor script reference:
90
90
@@ -105,7 +105,7 @@ Place the JavaScript tags (`<script>...</script>`) inside the [closing `</body>`
105
105
106
106
:::moniker range=">= aspnetcore-6.0"
107
107
108
-
###Load a script from an external JavaScript file (`.js`) collocated with a component
108
+
## Load a script from an external JavaScript file (`.js`) collocated with a component
@@ -170,15 +170,15 @@ For more information, see <xref:blazor/components/class-libraries>.
170
170
171
171
:::moniker range=">= aspnetcore-6.0"
172
172
173
-
###Inject a script before or after Blazor starts
173
+
## Inject a script before or after Blazor starts
174
174
175
175
To ensure scripts load before or after Blazor starts, use a JavaScript initializer. For more information and examples, see <xref:blazor/fundamentals/startup#javascript-initializers>.
176
176
177
177
:::moniker-end
178
178
179
179
:::moniker range="< aspnetcore-6.0"
180
180
181
-
###Inject a script after Blazor starts
181
+
## Inject a script after Blazor starts
182
182
183
183
To inject a script after Blazor starts, chain to the `Promise` that results from a manual start of Blazor. For more information and an example, see <xref:blazor/fundamentals/startup#inject-a-script-after-blazor-starts>.
0 commit comments