Skip to content

Commit 4088e5d

Browse files
authored
Merge pull request #1482 from Ghost-017/patch-4
minor
2 parents f0e848a + 58c91c3 commit 4088e5d

File tree

1 file changed

+9
-9
lines changed
  • 2-ui/5-loading/01-onload-ondomcontentloaded

1 file changed

+9
-9
lines changed

2-ui/5-loading/01-onload-ondomcontentloaded/article.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ In the example the `DOMContentLoaded` handler runs when the document is loaded,
4949

5050
But it doesn't wait for the image to load. So `alert` shows zero sizes.
5151

52-
At the first sight `DOMContentLoaded` event is very simple. The DOM tree is ready -- here's the event. There are few peculiarities though.
52+
At first sight, the `DOMContentLoaded` event is very simple. The DOM tree is ready -- here's the event. There are few peculiarities though.
5353

5454
### DOMContentLoaded and scripts
5555

@@ -75,8 +75,8 @@ In the example above, we first see "Library loaded...", and then "DOM ready!" (a
7575

7676
```warn header="Scripts that don't block DOMContentLoaded"
7777
There are two exceptions from this rule:
78-
1. Scripts with `async` attribute that we'll cover [a bit later](info:script-async-defer) don't block `DOMContentLoaded`.
79-
2. Scripts that are generated dynamically with `document.createElement('script')` and then added to page also don't block this event.
78+
1. Scripts with the `async` attribute, that we'll cover [a bit later](info:script-async-defer), don't block `DOMContentLoaded`.
79+
2. Scripts that are generated dynamically with `document.createElement('script')` and then added to the webpage also don't block this event.
8080
```
8181

8282
### DOMContentLoaded and styles
@@ -93,7 +93,7 @@ But there's a pitfall. If we have a script after the style, then that script mus
9393
</script>
9494
```
9595

96-
The reason is that the script may want to get coordinates and other style-dependent properties of elements, like in the example above. Naturally, it has to wait for styles to load.
96+
The reason for this is that the script may want to get coordinates and other style-dependent properties of elements, like in the example above. Naturally, it has to wait for styles to load.
9797

9898
As `DOMContentLoaded` waits for scripts, it now waits for styles before them as well.
9999

@@ -217,7 +217,7 @@ if (document.readyState == 'loading') {
217217
}
218218
```
219219
220-
There's also `readystatechange` event that triggers when the state changes, so we can print all these states like this:
220+
There's also the `readystatechange` event that triggers when the state changes, so we can print all these states like this:
221221
222222
```js run
223223
// current state
@@ -272,12 +272,12 @@ The numbers in square brackets denote the approximate time of when it happens. E
272272
273273
Page load events:
274274
275-
- `DOMContentLoaded` event triggers on `document` when DOM is ready. We can apply JavaScript to elements at this stage.
275+
- The `DOMContentLoaded` event triggers on `document` when the DOM is ready. We can apply JavaScript to elements at this stage.
276276
- Script such as `<script>...</script>` or `<script src="..."></script>` block DOMContentLoaded, the browser waits for them to execute.
277277
- Images and other resources may also still continue loading.
278-
- `load` event on `window` triggers when the page and all resources are loaded. We rarely use it, because there's usually no need to wait for so long.
279-
- `beforeunload` event on `window` triggers when the user wants to leave the page. If we cancel the event, browser asks whether the user really wants to leave (e.g we have unsaved changes).
280-
- `unload` event on `window` triggers when the user is finally leaving, in the handler we can only do simple things that do not involve delays or asking a user. Because of that limitation, it's rarely used. We can send out a network request with `navigator.sendBeacon`.
278+
- The `load` event on `window` triggers when the page and all resources are loaded. We rarely use it, because there's usually no need to wait for so long.
279+
- The `beforeunload` event on `window` triggers when the user wants to leave the page. If we cancel the event, browser asks whether the user really wants to leave (e.g we have unsaved changes).
280+
- `The unload` event on `window` triggers when the user is finally leaving, in the handler we can only do simple things that do not involve delays or asking a user. Because of that limitation, it's rarely used. We can send out a network request with `navigator.sendBeacon`.
281281
- `document.readyState` is the current state of the document, changes can be tracked in the `readystatechange` event:
282282
- `loading` -- the document is loading.
283283
- `interactive` -- the document is parsed, happens at about the same time as `DOMContentLoaded`, but before it.

0 commit comments

Comments
 (0)