Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POC: Playing around with defer / sync WP strategies #2273

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

GP-Dan-Tovbein
Copy link
Contributor

@GP-Dan-Tovbein GP-Dan-Tovbein commented Apr 26, 2024

Taken from here.

Demo page: https://www-dev.greenpeace.org/test-sinope/get-informed/

Description

As a part of an experiment, I've tested the functionality of defer/sync WordPress strategies by registering scripts.

1699370054733

According to the official Mozilla documentation:

Deferred scripts

Scripts marked for deferred execution — via the defer script attribute — are only executed once the DOM tree has fully loaded (but before the DOMContentLoaded and window load events). Deferred scripts are executed in the same order they were printed/added in the DOM, unlike asynchronous scripts.

Asynchronous scripts

Scripts marked for asynchronous execution — via the async script attribute — are executed as soon as they are loaded by the browser. Asynchronous scripts do not have a guaranteed execution order, as script B (although added to the DOM after script A) may execute first given that it may complete loading prior to script A. Such scripts may execute either before the DOM has been fully constructed or after the DOMContentLoaded event.

Potential ideas for solutions

Testing

  • Change browser throttling to Regular 2G, also test with Wi-Fi
  • Disable cache
  • If you clean cache and reload the page you'll see that the async element is not working always as expected

Conclusion

Of course defer is the best approach for loading JS scripts since we're ensure that we're able to interact with added into a DOM since it's been fully loaded. However, for scripts that are independent of other scripts, such as tracking scripts, async is the best approach

@GP-Dan-Tovbein GP-Dan-Tovbein added the PoC Pull requests that are defined as a proof of concept label Apr 26, 2024
@GP-Dan-Tovbein GP-Dan-Tovbein marked this pull request as draft April 26, 2024 17:18
@GP-Dan-Tovbein GP-Dan-Tovbein self-assigned this Apr 26, 2024
@GP-Dan-Tovbein GP-Dan-Tovbein changed the title POC: Playing around with defer and sync WP strategies POC: Playing around with defer / sync WP strategies Apr 26, 2024
planet-4 added a commit to greenpeace/planet4-test-sinope that referenced this pull request Apr 29, 2024
/unhold 3bbff2d7-80ab-450e-819b-e05dce83e97f
@planet-4
Copy link
Contributor

planet-4 commented Apr 29, 2024

Test instance is ready 🚀

🌑 sinope | admin | blocks report | CircleCI | composer-local.json

⌚ 2024.05.08 12:09:48

@GP-Dan-Tovbein GP-Dan-Tovbein force-pushed the experiment/async-defer-wp-strategies branch from 0f44f51 to 9103230 Compare May 8, 2024 10:29
planet-4 added a commit to greenpeace/planet4-test-sinope that referenced this pull request May 8, 2024
/unhold 355987ba-579c-4c32-bc55-f44be163e89d
planet-4 added a commit to greenpeace/planet4-test-sinope that referenced this pull request May 8, 2024
/unhold c6a65664-3e86-42a5-ac8b-251e69bee545
@GP-Dan-Tovbein GP-Dan-Tovbein force-pushed the experiment/async-defer-wp-strategies branch from 9103230 to 232869e Compare May 8, 2024 11:02
planet-4 added a commit to greenpeace/planet4-test-sinope that referenced this pull request May 8, 2024
/unhold ff409669-247a-4b68-b3ac-6d8ed5d751ea
@GP-Dan-Tovbein GP-Dan-Tovbein force-pushed the experiment/async-defer-wp-strategies branch from 232869e to f0346e2 Compare May 8, 2024 11:22
@GP-Dan-Tovbein GP-Dan-Tovbein force-pushed the experiment/async-defer-wp-strategies branch from f0346e2 to 7a26018 Compare May 8, 2024 11:49
planet-4 added a commit to greenpeace/planet4-test-sinope that referenced this pull request May 8, 2024
/unhold 9dbe7c4c-1c43-475c-89dd-f772f409f115
planet-4 added a commit to greenpeace/planet4-test-sinope that referenced this pull request May 8, 2024
/unhold 54f5f1e8-5112-4379-9db2-d9a4c7786713
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DO NOT MERGE PoC Pull requests that are defined as a proof of concept [Test Env] sinope
Projects
None yet
3 participants