All threads / How To Use Turbolinks clearCache() Discussion
Ask A Question


You’re not receiving notifications from this thread.

How To Use Turbolinks clearCache() Discussion

Alejandro Ventura ·

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 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)
Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 70,078+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

    © 2023 GoRails, LLC. All rights reserved.