Skip to main content

How To Use Turbolinks clearCache() Discussion

General • Asked by Chris Oliver

Does it works only for JS responses? Or it could be used in html responses and how to do that?

It's a Javascript method, so it must be done in Javascript. You only need to call this if data changes during a request. If you're making a POST/PUT/DELETE not via Javascript, you wouldn't need this because your browser will not be loading the next page view JS.


@excid3:disqus As far as I can tell the caching used by turbolinks is not available offline. Do you agree with this?

Well the turbolinks cache is designed to display the previous page quickly before refreshing it with the latest version. It's not designed for offline work, just to speed up the page.

Basecamp's mobile app basically just implements a "The internet connection appears to be offline" for pages and a reload button till the user is back online. ServiceWorkers in HTML5 are designed to help make offline functionality of web pages a bit better, but if it's a mobile app you may also want to build out some views natively so that they still function offline.

Thanks for taking the time to reply. It's worth noting also that ServiceWorkers currently aren't supported on iOS or Android webviews: https://developer.mozilla.o...

So my current conclusion (based on my current knowledge level) is if you want to adopt the "offline first" mentality with your native/hybrid mobile app then avoid Turbolinks 5 and instead look at other solutions (ie fully native in Swift, React Native with Realm, etc).

Yeah Turbolinks is not designed for mobile apps that need to work offline. It has basic fallbacks but it's intention is never to make fully offline mobile apps.

Do you have any thoughts about using an approach like https://github.com/meagar/r... to enable basic caching of assets?

Unfortunately AppCache was deprecated in favor of Service Workers due to some poor design they discovered on more complex apps. https://developer.mozilla.o... has the deprecation warnings at the top there.

Is there anything you don't know?

Hehe 😎 I actually saw that earlier when I was poking around the offline web app stuff on MDN when we were talking about ServiceWorkers. I haven't done a whole lot with stuff though, just dabbled.


Is there anyway to invoke this when moving between layouts? I often (but not always) need a screen refresh when moving from application.html.erb to admin.html.erb (different layout and stylesheets)

Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 24,647+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.