Turn off caching on Android for WebApps -


honestly, i'm unsure whether should post on so; either way, let's each other out.

i'm building web app regularly check on android phone, @ point. instead of uploading phonegap or time, i've configured simple page iframe pointing content of web app (hosted online).

the bad thing of this: in order see changes, have clean app cache. else, 'previous' version still showing (because it's stuck in cache).

so hoping if there option turn on/off on android/configure within page turns off caching objects , files?

thanks lot guys!

to give idea of how work..

 ------------------------------------------------- |                   phone                    | |                                        | |                                               | |   -----------------------------------------   | |   |           cordova/phonegap            |   | |   |           application           |   | |   |           loads                     |   | |   |                                       |   | |   |   --------------------------------    |   | |   |   |       website            |   |   | |   |   |       iframe                  |   |   | |   |   |       height:100%             |   |   | |   |   |       width:100%              |   |   | |   |   |                               |   |   | |   |   |   -------------------------   |   |   | |   |   |   |                       |   |   |   | |   |   |   |       html5           |   |   |   | |   |   |   |       responsive      |   |   |   | |   |   |   |       webpage         |   |   |   | |   |   |   |   (the webapp itself) |   |   |   | |   |   |   |                       |   |   |   | |   |   |   -------------------------   |   |   | |   |   |                               |   |   | |   |   |                               |   |   | |   |   ---------------------------------   |   | |   |                                       |   | |   ----------------------------------------    | |                                               | ------------------------------------------------- 

there 2 ways disable caching on cordova/phonegap apps.

  1. first 1 configuring webview settings while loading content.
  2. second 1 adding timestamp value url everytime want refresh page. more workaround.

i'll describe both options in detail.

first solution

for new version of cordova (5.3.3)

add below imports

import android.webkit.websettings; import android.webkit.webview; 

override onresume this-

@override protected void onresume() {     super.onresume();     // disable caching ..      webview wv = (webview) appview.getengine().getview();     websettings ws = wv.getsettings();      ws.setappcacheenabled(false);      ws.setcachemode(websettings.load_no_cache);     loadurl(launchurl); // launchurl default url specified in config.xml } 

=======

for older versions of cordova

assuming you're loading content on activity class.

you able configure webview while it's loaded on activity class.

here sample code snippet can understand how disable browser caching in phonegap/cordova apps.

public class mainactivity extends droidgap {     @override     protected void onresume() {         super.onresume();         // disable caching ..          super.appview.getsettings().setappcacheenabled(false);          super.appview.getsettings().setcachemode(websettings.load_no_cache);         super.loadurl("http://blabla.com");     } } 

as can see, code block load content whenever onresume() event triggered means web content reloaded whenever app in foreground.

following piece of code prevents caching on webview.

super.appview.getsettings().setappcacheenabled(false);  super.appview.getsettings().setcachemode(websettings.load_no_cache); 

second solution

this solution silly behaves expected. situation, may helpful.

you can add timestamp value @ end of url. here sample code snippet.

public class mainactivity extends droidgap {      @override     protected void onresume() {         super.onresume();          stringbuilder urlbuilder = new stringbuilder("http://blabla.com");         urlbuilder.append("?timestamp=");         urlbuilder.append(new date().gettime());         super.loadurl(urlbuilder.tostring());      } } 

it appends timestamp value @ end of url everytime , loads content it's new.

these 2 ways avoid caching in web apps in phonegap/cordova.

hope may helpful.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

javascript - Ajax jqXHR.status==0 fix error -

firefox - How do I check if firebug is installed with javascript? -