Skip to content

Commit

Permalink
Docs(upgrade): Add DOMContentLoaded recommendation #CCM-57
Browse files Browse the repository at this point in the history
  • Loading branch information
OndraM committed Feb 10, 2022
1 parent d949bc0 commit d98b306
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions UPGRADE-2.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,27 @@ This guide will help you upgrade your codebase.

TBD

## Use `DOMContentLoaded` event instead of `load`

It is highly recommended changing the event where plugin initialization is placed to `DOMContentLoaded`:

```diff
<script>
-window.addEventListener('load', function () {
+window.addEventListener('DOMContentLoaded', function () {
initLmcCookieConsentManager('demo.example');
});
</script>
```

This will lead to a faster start and rendering of the cookie consent, because unlike `load`, the `DOMContentLoaded`
event (see [MDN docs](https://developer.mozilla.org/en-US/docs/Web/API/Document/DOMContentLoaded_event)) does not wait
for loading of other page resources (like images).

When loading the plugin from a standalone file or CDN, you should keep using the `defer` attribute of `<script>`.
Scripts with `defer` are also loaded before `DOMContentLoaded` event
(see [MDN docs](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-defer)).

## Adjust design of the new Settings Modal

While the new Settings Modal inherits many design choices from the existing theme, you may still need to adjust it
Expand Down

0 comments on commit d98b306

Please sign in to comment.