What is the right way to load external JS and widget in template?

Technical Support
  • Is there a way to include external js for widgets like : https://www.tradingview.com/widget/ in template . Because when I try it, on first load it shows only the widget and nodebb page does not load, on refresh it loads the page also.
    Thanks

  • I see the same issue happens when pasting the code they give in a html widget .

  • Load it with require(), and make sure you specify a container for it.

    This works in an HTML widget:

    <div id="widget-frame-container"></div> // The container
    
    <script type="text/javascript">
    require(["https://d33t3vvu2t2yu5.cloudfront.net/tv.js"], function () {
    new TradingView.widget({
      "container_id": "widget-frame-container",           // Make sure you have this part
      "width": 998,
      "height": 610,
      "symbol": "FX:SPX500",
      "interval": "D",
      "timezone": "exchange",
      "theme": "White",
      "style": "1",
      "toolbar_bg": "#f1f3f6",
      "allow_symbol_change": true,
      "hideideas": true,
      "show_popup_button": true,
      "popup_width": "1000",
      "popup_height": "650"
    });
    });
    </script>
    
  • Do you mean that simply adding the Javascript / HTML code in the HTML Widget does not work?

    Is it a must to use "require" on the html widget for external Javascript which is needed on the client side?

    @psychobunny do you think this is what is causing my adsense related problems?

  • I've manually put in external <script> tags and they've worked, it probably won't work if it needs to be in the <head>, in that case you should put that bit in the custom HTML page in the ACP

  • Ok. Will try and see if this improves the render / load.


Suggested Topics