Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google chart not loaded when connecting to /home/index from link #1

Closed
sic2 opened this issue Jul 12, 2016 · 3 comments
Closed

Google chart not loaded when connecting to /home/index from link #1

sic2 opened this issue Jul 12, 2016 · 3 comments

Comments

@sic2
Copy link
Member

sic2 commented Jul 12, 2016

How to reproduce:

  1. Go to any other page other than the home page
  2. Go back to the homepage via the 'ISAMUNI' link (top-left)

Output: no google chart


I believe the problem is that we are just making the @posts and @post_jobs objects on home#index (controller) and not invoking any js of that page.

@vigliag
Copy link
Member

vigliag commented Jul 14, 2016

This is a javascript problem, and causes this error:
google.charts.load() cannot be called more than once with version 45 or earlier.
which happens because of turbolinks https://github.com/turbolinks/turbolinks .

Turbolinks is a method to make pages load faster by making ajax requests and replacing the body of the page. This way the browser doesn't have to reload the

and the tag.
Because of Turbolinks we are effectively always on the same page (home) and the others are loaded via js. This means that we start in home, the google charts js gets executed the first time, and remains in ram, so that when we visit the page again, the body is re-executed, but it finds the google charts library already loaded and complains.
The solutions are:

  • moving that code (or at least the google.charts.load() part) in a tag in the header (which isn't re-executed because it is only loaded once). Note that the chart, instead, should be redrawn on every visit. This means we should have some part of the code either in a 'script' tag in the body or wrapped in a turbolinks:load event listener. This may be tricky.
  • disabling turbolinks altogether (which we can very well do, especially because we are not so concerned with performances right now)

@sic2
Copy link
Member Author

sic2 commented Jul 14, 2016

I get that!

On one hand: yes, lets disable turbolinks! But I do not want to make the webapp too slow. One think is having the app tested locally, but once deployed I would not be surprised to see event 30-50+ people there at the same time (expecially on day-0). Not big numbers, but who knows...

Can't we have the js code in the layout.js file?

Note that the chart, instead, should be redrawn on every visit.
The onLoad() function will not work I guess, but rails might have something for us. I will look for that.

@sic2
Copy link
Member Author

sic2 commented Jul 16, 2016

Solved with commit:
fd97e72

@sic2 sic2 closed this as completed Jul 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants