> For the complete documentation index, see [llms.txt](https://docs.abtasty.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.abtasty.com/client-side/tag/troubleshootings/implementing-locking-mechanism-for-ssr.md).

# 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](/client-side/tag/tag-methods-variables.md#locking-tag-execution) 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

{% code title="\_document.tsx" fullWidth="false" %}

```javascript
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>
  );
}
```

{% endcode %}

{% code title="\_app.tsx" %}

```javascript
import { useEffect } from 'react';

function MyApp({ Component, pageProps }) {
  useEffect(() => {
    const tryUnlockABTasty = () => {
      if (typeof window?.unlockABTasty === 'function') {
        window.unlockABTasty();
      } else {
        setTimeout(tryUnlockABTasty, 100);
      }
    };
    tryUnlockABTasty();
  }, []);

  return <Component {...pageProps} />;
}

export default MyApp;
```

{% endcode %}

### Angular

{% code title="Index.html" %}

```javascript
<head>
  <script>
    window.lockABTastyTag = true;
  </script>
</head>
```

{% endcode %}

{% code title="app.component.ts" %}

```javascript
import { AfterViewInit, Component } from '@angular/core';

@Component({
  selector: 'app-root',
  template: `<router-outlet></router-outlet>`
})
export class AppComponent implements AfterViewInit {
  ngAfterViewInit(): void {
    const tryUnlockABTasty = () => {
      if (typeof window.unlockABTasty === 'function') {
        window.unlockABTasty();
      } else {
        setTimeout(tryUnlockABTasty, 100);
      }
    };
    tryUnlockABTasty();
  }
}
```

{% endcode %}

### VueJS

{% code title="nuxt.config.js" %}

```javascript
export default {
  app: {
    head: {
      script: [
        { children: 'window.lockABTastyTag = true;' }
      ]
    }
  }
}
```

{% endcode %}

{% code title="App.vue" %}

```javascript
export default {
  mounted() {
    if (typeof window !== 'undefined' && window.unlockABTasty) {
      window.unlockABTasty();
    }
  }
}
```

{% endcode %}

### Vanilla JS

{% code title="index.html" %}

```javascript
<head>
  <!-- Lock AB Tasty before the tag loads -->
  <script>
    window.lockABTastyTag = true;
  </script>

  <!-- AB Tasty tag here -->
  <script src="https://try.abtasty.com/.../abtasty.js" async></script>
</head>
```

{% endcode %}

{% code title="script.js" %}

```javascript
window.addEventListener("DOMContentLoaded", function () {
  if (typeof window.unlockABTasty === "function") {
    window.unlockABTasty();
  }
});

```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.abtasty.com/client-side/tag/troubleshootings/implementing-locking-mechanism-for-ssr.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
