lazy_high_charts icon indicating copy to clipboard operation
lazy_high_charts copied to clipboard

Charts rendered only when browser refreshes when using page caching

Open lamoglia opened this issue 8 years ago • 7 comments

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 avatar May 02 '16 14:05 lamoglia

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.

lamoglia avatar May 02 '16 17:05 lamoglia

@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.

Goncalo-Almeida avatar Sep 16 '16 14:09 Goncalo-Almeida

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'

lamoglia avatar Sep 16 '16 16:09 lamoglia

cool, if the tips is good, please pr.

xiaods avatar Sep 17 '16 11:09 xiaods

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

lamoglia avatar Sep 18 '16 00:09 lamoglia

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 avatar Sep 18 '16 01:09 Goncalo-Almeida

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

Goncalo-Almeida avatar Sep 19 '16 08:09 Goncalo-Almeida