Rails -- Google Charts loader.js can only be loaded once (not a duplicate question)

146 views
Skip to first unread message

Steven Gissubel

unread,
Nov 10, 2017, 2:31:04 PM11/10/17
to Google Visualization API
I have read the previous discussions on this issue -- but none seem to relate entirely. 


I am getting the response ""Google Charts loader.js can only be loaded once.""  Every time that I load a new page. 

But, the curious part is, I am calling ```google.charts.load('current', {packages: ['corechart']});``` only in one place tucked inside of an AJAX call that is only called in one specific area of my code on one specific page. Inserting debugger just before it -- this is clear.  It only gets hit when I make that AJAX call.

Tracing the flow, I found that the error is appearing when it loads my script tag for google charts.  I have the script tag written into my application-html-frame for the entire site (so as it houses every subsequent page, it is loaded every time that I load a new page).  
The error arises when it hits (loader.js) -- I'm assuming through running the script tag. 

Any thoughts on how to avoid this issue?

Thank you
Message has been deleted

Steven Gissubel

unread,
Nov 10, 2017, 2:58:59 PM11/10/17
to Google Visualization API
Figured out a solution. 

(working with html.slim)... I was originally loading the script with other javascript scripts...

  body
   
= render 'layouts/header'
   
= yield
   
= render 'layouts/footer'



   
.javascript
     
= yield :javascript
     
= javascript_include_tag "https://www.gstatic.com/charts/loader.js"
     
= javascript_include_tag 'application', 'data-turbolinks-track' => true



Altered it so that it stood alone in the header (as noted in documentation). 

 
 head
    script src
="https://www.gstatic.com/charts/loader.js" type="text/javascript"
    title 
Learning Management System
    
= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true
    
= csrf_meta_tags
    link rel
="apple-touch-icon" href=(image_path('apple-touch-icon.png'))



Just in case anyone runs into a similar issue. 
Reply all
Reply to author
Forward
0 new messages