Skip to content

Commit 9214ff5

Browse files
authored
Update script tag location guidance (#34346)
1 parent f538c9a commit 9214ff5

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

aspnetcore/blazor/javascript-interoperability/location-of-javascript.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@ Load JavaScript (JS) code using any of the following approaches:
3333

3434
:::moniker-end
3535

36+
## Location of `<script>` tags
37+
3638
:::moniker range=">= aspnetcore-8.0"
3739

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.
4041

4142
:::moniker-end
4243

4344
:::moniker range="< aspnetcore-8.0"
4445

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.
4747

4848
:::moniker-end
4949

@@ -61,7 +61,7 @@ Load JavaScript (JS) code using any of the following approaches:
6161
6262
:::moniker-end
6363

64-
### Load a script in `<head>` markup
64+
## Load a script in `<head>` markup
6565

6666
*The approach in this section isn't generally recommended.*
6767

@@ -84,7 +84,7 @@ Loading JS from the `<head>` isn't the best approach for the following reasons:
8484
* 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.
8585
* The page may become interactive slower due to the time it takes to parse the JS in the script.
8686

87-
### Load a script in `<body>` markup
87+
## Load a script in `<body>` markup
8888

8989
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:
9090

@@ -105,7 +105,7 @@ Place the JavaScript tags (`<script>...</script>`) inside the [closing `</body>`
105105

106106
:::moniker range=">= aspnetcore-6.0"
107107

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
109109

110110
[!INCLUDE[](~/blazor/includes/js-interop/js-collocation.md)]
111111

@@ -170,15 +170,15 @@ For more information, see <xref:blazor/components/class-libraries>.
170170

171171
:::moniker range=">= aspnetcore-6.0"
172172

173-
### Inject a script before or after Blazor starts
173+
## Inject a script before or after Blazor starts
174174

175175
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>.
176176

177177
:::moniker-end
178178

179179
:::moniker range="< aspnetcore-6.0"
180180

181-
### Inject a script after Blazor starts
181+
## Inject a script after Blazor starts
182182

183183
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>.
184184

0 commit comments

Comments
 (0)