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

Can we ditch the document observer and put the script at the bottom of the page? #13

Open
AndyStabler opened this issue Apr 30, 2018 · 0 comments

Comments

@AndyStabler
Copy link
Owner

What are we currently doing?

Currently we're being smart with document observers and doing the following:

  1. Andy AB script is added to the <head>
  2. User sets up the experiment, adding the experiment cohorts and conditions on which to change elements of the page
  3. A document observer starts to listen to the DOM as it loads (but before rendering)
  4. If the document observer finds an element in the DOM it thinks it should change, then it swaps out the DOM element
  5. The DOM finishes loading and we unregister the document observers
  6. The page is rendered

What could we do?

I wonder if we could achieve the same result by just putting the script at the bottom of the page

  1. Andy AB script added to bottom of the <body> tag
  2. User sets up the experiment, adding the experiment cohorts and conditions on which to change elements of the page
  3. Andy AB looks for, and changes, any elements in the DOM that should change.
  4. The DOM finishes loading (the script was at the bottom of the file anyway?)
  5. The page is rendered

Why is the document observer better?

  • it listens to the DOM and takes action if it finds an element it thinks should change. This might be useful if another script loads and changes the DOM.

Why is putting the script at the bottom of the body tag better?

  • Generally good practice to place scripts at the end of body.
  • We could remove a fair bit of document observer code

Open questions

  • Could placing the script in the body tag cause flickering? The DOM loads, begins to render, then the script loads and swaps out elements.
    • Off the top of my head this shouldn't happen– rendering is blocked until scripts are loaded and executed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant