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

Charts rendered only when browser refreshes when using page caching #212

Open
lamoglia opened this issue May 2, 2016 · 7 comments
Open

Comments

@lamoglia
Copy link

lamoglia commented May 2, 2016

I noticed that when I'm using page caching (gem 'actionpack-page_caching'), the charts are rendered only when a full refresh is made (i.e. not when navigating to the chart page using internal links, only when pressing f5).
I think it may be something related to encapsulate_js method in layout_helper.rb : it checks for the referrer (request_is_referrer) to conditionally renders a block of js, and when the page is fully cached, it doesn't have the chance to render it differently on the second call (when not refreshing).

Anyone already experienced this? Any thoughts on using page caching with lazy_highcharts?

@lamoglia
Copy link
Author

lamoglia commented May 2, 2016

I've managed to instantiate the charts using jquery $(document).ready. It allows this gem to work with rails page caching.
It seems that some work was made for not relying on jquery to include the charts, but it leaves this functionality gap for cached pages.

@Goncalo-Almeida
Copy link

@lamoglia could you please explain exactly how you implemented this?

I'm having the same issue but I fail to understand how to instantiate the chart using jquery.

Thank you in advance.

@lamoglia
Copy link
Author

I've forked this repo and changed how the chart is inserted and the specs (see commit https://github.com/lamoglia/lazy_high_charts/commit/011af5f7574b678c4fb5d35c5b579c90bbc663c2).
Then, in my app I'm using this forked version. You can test if it works for you changing the lazy_high_charts dependency in your gemfile:

gem 'lazy_high_charts', :git => 'git://github.com/lamoglia/lazy_high_charts.git'

@xiaods
Copy link
Collaborator

xiaods commented Sep 17, 2016

cool, if the tips is good, please pr.

@lamoglia
Copy link
Author

Sure. Did it work for you @Goncalo-Almeida ?

@Goncalo-Almeida
Copy link

Sorry for the delayed response.
First, thank you for your answer.
I haven't tested it yet. I'm only able to test this next Monday.
I'll report back first thing in the morning.

@Goncalo-Almeida
Copy link

Hi! Thanks for this @lamoglia :)
Worked like a charm 👍

@lamoglia lamoglia mentioned this issue Sep 19, 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

3 participants