# Cross-Origin hosting

## Overview

By default, the library expects its static files to be hosted on the same origin (domain) as the page that contains the chart.
If you host library files on a different origin, follow the configuration steps below.

:::info

The TradingView [demo storage server] (`https://saveload.tradingview.com`) accepts requests only from `localhost` and `tradingview.com` origins.
It does not support cross-origin setups for other domains.
For production, implement your own storage backend.
For details, see [Saving and loading charts].

:::

## 1. Load the standalone script

Add the script tag within the `<head>` of the page.

```html
<script
    type="text/javascript"
    src="https://example.com/charting_library/charting_library.standalone.js"
></script>
```

## 2. Configure the widget constructor

When creating the widget, set [`library_path`] to the **absolute URL** of the folder that contains the library static files.
Note the following:

- The URL must start with `http://` or `https://`.
- The URL must end with a trailing forward slash `/`.

Example:

```javascript
const widget = new TradingView.widget({
    // highlight-next-line
    library_path: 'https://example.com/charting_library/',
    symbol: 'AAPL',
    interval: '1D',
    container: 'tv_chart_container',
    datafeed: new Datafeeds.UDFCompatibleDatafeed("https://demo-feed-data.tradingview.com"),
});
```

## 3. Configure CORS

Because the library fetches resources from the [`library_path`], your remote server must allow Cross-Origin Resource Sharing (CORS).
Make sure that the server hosting the library files is configured to allow Cross-Origin requests from the origin of the page containing the chart element.
Otherwise, the browser may block internal library resources, causing a blank chart or console errors.
For guidance, see [Access-Control-Allow-Origin header].

[Access-Control-Allow-Origin header]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin
[demo storage server]: https://charting-library-docs.xstaging.tv/latest/saving_loading/save-load-rest-api.md#use-demo-storage
[`library_path`]: https://charting-library-docs.xstaging.tv/latest/api/interfaces/Charting_Library.ChartingLibraryWidgetOptions#library_path
[Saving and loading charts]: https://charting-library-docs.xstaging.tv/latest/saving_loading.md

---

## Sitemap

- [All documentation pages](https://charting-library-docs.xstaging.tv/llms.txt)
- [Full page map with headings](https://charting-library-docs.xstaging.tv/docs_map.md)
