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.
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.
<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://orhttps://. - The URL must end with a trailing forward slash
/.
Example:
const widget = new TradingView.widget({
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.