Hosting Library Cross Origin - SpartaCommodities/Trading_view_wiki GitHub Wiki
If you need to host the library files on a separate origin (domain) to the page
containing the chart then please ensure that the
library_path widget constructor parameter
is configured as follows:
- The
library_pathvalue should start with eitherhttp://orhttps://, followed by the url to the folder containing the charting library's static files.- example:
library_path: 'https://example.com/charting_library/'
- example:
-
library_pathshould end with a trailing forward slash.
If you hosted the library files within a folder named charting_library on the
example.com domain then you would configure the library as follows.
Place the following script tag within the <head> of the page.
<script
type="text/javascript"
src="https://example.com/charting_library/charting_library.standalone.js"
></script>When evoking the widget constructor, ensure that the library_path value starts
with http as described above.
var widget = (window.tvWidget = new TradingView.widget({
library_path: 'https://example.com/charting_library/',
symbol: 'A',
interval: '1D',
container: 'tv_chart_container',
datafeed: new Datafeeds.UDFCompatibleDatafeed(
'https://demo_feed.tradingview.com'
),
}));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. Please see this MDN article for more information: Access-Control-Allow-Origin
Please note that the
demo charts and study template storage server
(http://saveload.tradingview.com) isn't compatible with requests from any
origin except localhost and tradingview.com. Attempting to use this server
from any other origin will still result in a CORS error.
Please see Saving and Loading Charts for an overview on how to setup your own storage server.