Skip to content

Commit f14be15

Browse files
committed
docs: update example <script> loading strategy
In the code examples, a <script> tag is placed just before the ending </body> tag. This causes the script's external resource to download and execute only after the HTML has been parsed up to that point. For organization and faster script evaluation, we can consolidate scripts in the <head> and enable their defer attribute, which will download the external resource in parallel with HTML parsing. Once the HTML is parsed, the deferred script will execute.
1 parent a77f7fb commit f14be15

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/content/guides/getting-started.mdx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ contributors:
2727
- d3lm
2828
- snitin315
2929
- Etheryen
30+
- zowiebeha
3031
---
3132

3233
Webpack is used to compile JavaScript modules. Once [installed](/guides/installation), you can interact with webpack either from its [CLI](/api/cli) or [API](/api/node). If you're still new to webpack, please read through the [core concepts](/concepts) and [this comparison](/comparison) to learn why you might use it over the other tools that are out in the community.
@@ -90,10 +91,10 @@ document.body.appendChild(component());
9091
<head>
9192
<meta charset="utf-8" />
9293
<title>Getting Started</title>
93-
<script src="https://unpkg.com/lodash@4.17.20"></script>
94+
<script defer src="https://unpkg.com/lodash@4.17.20"></script>
95+
<script defer src="./src/index.js"></script>
9496
</head>
9597
<body>
96-
<script src="./src/index.js"></script>
9798
</body>
9899
</html>
99100
```
@@ -191,11 +192,11 @@ Now, since we'll be bundling our scripts, we have to update our `index.html` fil
191192
<head>
192193
<meta charset="utf-8" />
193194
<title>Getting Started</title>
194-
- <script src="https://unpkg.com/lodash@4.17.20"></script>
195+
- <script defer src="https://unpkg.com/lodash@4.17.20"></script>
196+
- <script defer src="./src/index.js"></script>
197+
+ <script defer src="main.js"></script>
195198
</head>
196199
<body>
197-
- <script src="./src/index.js"></script>
198-
+ <script src="main.js"></script>
199200
</body>
200201
</html>
201202
```

0 commit comments

Comments
 (0)