1

So I am able to get my page to prefetch with the following:

<link rel="prerender prefetch" href="<%= request.base_url + @prerender %>" as="HTML">

However it only seems to load the layout and not the API call I have in the rails controller. I am using a cURL call to a third party API for displaying a gif that shows the weather radar. This is all supposed to function on a loop of several pages (15 seconds each) and I want the next page (with API call) to load while the current one is displaying for ~15 seconds because the API call takes around 5 seconds.

I don't want 1/3 of the display time to be blank but it seems that prerender isn't running the Rails controller or cURL call. Does it not function this way or am I doing something wrong? I've tried prerender and prefetch by themselves as well as together. I've also tried various values for the as="" attribute.

This is my first stackoverflow post so I hope I was clear enough

Alex R.
  • 11
  • 2

2 Answers2

0

Found a related question/answer that solved my problem. I'm calling the API ahead of time and saving the gif (overriding the old one every time to save space) so I can just link to the file within the project.

Best practice for Rails third party API calls?

Alex R.
  • 11
  • 2
0

Since you said that the layout was prefetched, I suppose the content is fetched and embedded after fetching via JS. If so, the prefetch feature doesn't execute JS (neither download JS, CSS, image files). It might be a reason why you only see the layout.

In general, your intention to prefetch the next page is one of goals of my project https://github.com/sirko-io/engine. You can try it out and give your feedback. It is an opensource project.

Dmytro Nesteriuk
  • 8,315
  • 1
  • 18
  • 14