Implementing locking mechanism for SSR

In case you want to implement AB Tasty in a server-side rendering (SSR) environment, you might want to use our locking mechanism to prevent our tag from executing and modify the DOM before it fully loads, thus avoiding any reconciliation issues.

You will find here basic implementation examples for the three main JS frameworks and vanilla JS.

Next JS

_document.tsx
import { Html, Head, Main, NextScript } from 'next/document';

export default function Document() {
  return (
    <Html>
      <Head>
        {/* Lock AB Tasty before tag loads */}
        <script>{`window.lockABTastyTag = true;`}</script>
      </Head>
      <body>
        <Main />
        <NextScript />
      </body>
    </Html>
  );
}

Angular

VueJS

Vanilla JS

Last updated

Was this helpful?