# Gravity Field Scripts Workflow

### Plug-in scripts

1. **Core.js** - core library.
2. **Dynamic.js** - stores information about campaigns, evaluators, strategies, and settings. It can be called from the core, where it will be an asynchronous load, or it can be embedded in the code and loaded synchronously through [Sync load](#sync-load).
   1. In the case of an asynchronous load, the website's loading speed is higher; however, there is also a higher probability of flickering.
   2. In the case of a synchronous load, the probability of flickering is lower, but the site's loading speed is impacted.

### Script Execution

1. A section is created in the admin panel of the personalization platform. When creating a section, its ID is generated along with an empty `dynamic.js` file.
2. Code snippet is deployed to the site code:

{% code overflow="wrap" %}

```javascript
<script>
window.GF = window.GF || {};
GF.section = "[SECTION_ID]";
GF.pageContext = { type: "OTHER", data: [] };
</script>
<script type="text/javascript" src="//cdn-01.gravityfield.ai/core/core.js"></script>
```

{% endcode %}

The snippet includes the `core.js` script, which is the core of the application and dynamically loads the required `dynamic.js -` a separate script which is created for each section and contains JSON data with campaigns and settings specific to that section.

#### Sync Load

There is an option for synchronous script loading - Sync Load. It is used in cases when you need minimalized campaign flickering.

```javascript
<script>
window.GF = window.GF || {};
GF.section = "[SECTION_ID]";
GF.pageContext = { type: "OTHER", data: [] };
GF.syncLoad = true;
</script>
<script type="text/javascript" src="//cdn-01.gravityfield.ai/core/core.js"></script>
<script type="text/javascript" src="//cdn-01.gravityfield.ai/sections/[SECTION_ID]/dynamic.js"></script>
```

### The Order of Script Execution

Core.js + dynamic.js sends a request to evs-01.gravityfield.ai to retrieve user data. This request is necessary to obtain a user's data and is created on every page load.

When the user interacts with the website, predefined events configured during integration will be sent. [3. Events](/lang/en/implementation/client-side-integration/3.-events.md)

### Prefetch and Preconnect

Dns-prefetch tags should be placed before the script to reduce DNS response time.

Preconnect tags allow the browser to set up a connection even before sending an HTTP request to the server. This helps to avoid delays and saves time for users. Some browsers (Internet Explorer, Safari) do not support preconnect tags and will ignore them.

These four tags should be included on every page of the website:

```jsx
<link rel="preconnect" href="//cdn-01.gravityfield.ai">
<link rel="preconnect" href="//evs-01.gravityfield.ai">
<link rel="dns-prefetch" href="//cdn-01.gravityfield.ai">
<link rel="dns-prefetch" href="//evs-01.gravityfield.ai">
```

### Platform Domains

Two domains are used for the operation of the personalization platform:

[evs-01.gravityfield.ai](https://evs-01.gravityfield.ai) — server queries

[cdn-01.gravityfield.ai](https://cdn-01.gravityfield.ai) — CDN

### Script Execution Dependency

All scripts are executed only after all user data has been received. In the future, it may be possible to implement a scenario where campaigns are launched step by step depending on the reception of the data required for their operation.

<figure><img src="/files/4bYg0jWlIjq8vo8jbVmt" alt=""><figcaption></figcaption></figure>

The dynamic.js script is updated with the updates of its components:&#x20;

* Campaigns
* Audiences
* Strategies etc.

The core.js script is updated with releases of new versions of platform.

**Scripts caching:**

* dynamic.js - 5 minutes
* core.js - 1 hour

### Cookie management

&#x20;The personalization platform uses 4 cookie files:

| Cookie         | Functionality                              | Domain        | Example value                                                    | TTL      |
| -------------- | ------------------------------------------ | ------------- | ---------------------------------------------------------------- | -------- |
| \_slid         | user ID                                    | .yoursite.net | 6343ff0e728f987d7c02325a                                         | 365 days |
| \_slid\_server | the same user ID in the first-party cookie | .yoursite.net | 6343ff0e728f987d7c02325a                                         | 365 days |
| \_slsession    | session ID                                 | .yoursite.net | C2A1D08D-BA49-43CF-9BB3-047030084FCF                             | 365 days |
| \_slfreq       | campaign frequency data                    | .yoursite.net | 6347f312d9062ed0380b52dc%3A6347f38c9a3f3b9e90027775%3A1667310093 | 365 days |


---

# Agent Instructions: 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:

```
GET https://developer.gravityfield.ai/lang/en/implementation/client-side-integration/1.-gravity-field-script/scripts.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
