> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ad-unblock.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Fetch Config

> Fetch AdUnblock latest configuration

# Configuration API Reference

The AdUnblock Configuration API provides access to the latest JavaScript configuration files needed for ad blocker detection on your website.

## Base URL

```
https://public.adunblocker.com
```

## Authentication

This API endpoint is publicly accessible and does not require authentication.

## Caching

The API responses are cached for optimal performance and support standard HTTP caching headers for efficient client-side caching.

## Server Tag Configuration

### Get JavaScript Configuration

Retrieve the latest JavaScript files needed for ad blocker detection.

<CodeGroup>
  ```bash cURL theme={null}
  curl -X GET https://public.adunblocker.com/api/vendor_scripts
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch("https://public.adunblocker.com/api/vendor_scripts");
  const scripts = await response.json();
  ```

  ```python Python theme={null}
  import requests

  response = requests.get('https://public.adunblocker.com/api/vendor_scripts')
  scripts = response.json()
  ```
</CodeGroup>

#### Response

```json theme={null}
["https://cdn.example.com/detection-script.js"]
```

#### Response Format

The response is a JSON array containing JavaScript file URLs for ad blocker detection as strings.

#### Response Headers

| Header          | Description                                       |
| --------------- | ------------------------------------------------- |
| `Content-Type`  | `application/json`                                |
| `ETag`          | Entity tag for caching validation                 |
| `Last-Modified` | Timestamp when the configuration was last updated |

#### Usage Example

Once you fetch the configuration, you can dynamically load the JavaScript files:

```javascript theme={null}
// Fetch configuration
const scripts = await fetch(
  "https://public.adunblocker.com/api/vendor_scripts"
).then((response) => response.json());

// Load the JavaScript files
scripts.forEach((scriptUrl) => {
  const script = document.createElement("script");
  script.src = scriptUrl;
  script.async = true;
  document.head.appendChild(script);
});
```

#### Caching Recommendations

* The API supports standard HTTP caching headers
* Implement conditional requests using `If-None-Match` header with ETag
* Cache responses locally for better performance
* Check for updates periodically (e.g., every hour)

```javascript theme={null}
// Example with conditional request
const etag = localStorage.getItem("config-etag");
const headers = etag ? { "If-None-Match": etag } : {};

const response = await fetch("https://public.adunblocker.com/api/vendor_scripts", {
  headers,
});

if (response.status === 304) {
  // Use cached configuration
  console.log("Configuration unchanged");
} else {
  // Update cache
  const scripts = await response.json();
  localStorage.setItem("config-etag", response.headers.get("ETag"));
  localStorage.setItem("config-data", JSON.stringify(scripts));
}
```

## Valid Script Sources (Deprecated)

<Warning>
  This endpoint is deprecated and will be removed in a future version. Please
  use the `/api/vendor_scripts` endpoint instead.
</Warning>

### Get Valid Script Sources

Retrieve a list of valid JavaScript source URLs for ad blocker detection.

<CodeGroup>
  ```bash cURL theme={null}
  curl -X GET https://config.adunblocker.com/valid_script_sources.json
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch(
    "https://config.adunblocker.com/valid_script_sources.json"
  );
  const sources = await response.json();
  ```

  ```python Python theme={null}
  import requests

  response = requests.get('https://config.adunblocker.com/valid_script_sources.json')
  sources = response.json()
  ```
</CodeGroup>

#### Response

```json theme={null}
["https://cdn.example.com/detection-script.js"]
```

#### Response Format

The response is a JSON array containing valid JavaScript source URLs as strings.

#### Response Headers

| Header          | Description                                       |
| --------------- | ------------------------------------------------- |
| `Content-Type`  | `application/json`                                |
| `ETag`          | Entity tag for caching validation                 |
| `Last-Modified` | Timestamp when the configuration was last updated |

#### Migration Guide

If you're currently using this endpoint, migrate to the new `/api/vendor_scripts` endpoint:

```javascript theme={null}
// Old (deprecated)
const sources = await fetch(
  "https://config.adunblocker.com/valid_script_sources.json"
).then((response) => response.json());

// New (recommended)
const scripts = await fetch(
  "https://public.adunblocker.com/api/vendor_scripts"
).then((response) => response.json());
// scripts is already an array, no need to access .js property
```
