android - How to enable expires-header caching for webview -


i building app consists of menu , webview. when user selecting menu items, webview should load respecting html file. far good.

now experiencing, webview requesting html each time pressing menu item. load html once in session, cause html files wont change during day. first thing did set expires header correctly on server side. can check here:

http://redbot.org/?uri=http%3a%2f%2fcutoutcam.com%2ftest1.php

then tried

mwebview.getsettings().setcachemode(websettings.load_default); 

and

mwebview.getsettings().setcachemode(websettings.load_cache_only); 

results:

first version requests html each time (checked proxy) -> that's weird. should show cached version long it's not expired. what's problem?

second version never requests new html file (thats ok, cause it's supposed to that)

anyone has idea why expires header not work here correctly?

the whole code:

mwebview = (webview) getview().findviewbyid(r.id.fragment_web_view_wv); mwebview.setwebviewclient(new webviewclient(this)); mwebview.setscrollbarstyle(view.scrollbars_outside_overlay);    mwebview.setwebchromeclient(new webchromeclient() {       @override       public void onreachedmaxappcachesize(long spaceneeded, long totalusedquota,               android.webkit.webstorage.quotaupdater quotaupdater)       {             quotaupdater.updatequota(spaceneeded * 2);       } });  mwebview.getsettings().setdomstorageenabled(true);   mwebview.getsettings().setappcachemaxsize(1024*1024*8);   string appcachepath = getactivity().getapplicationcontext().getcachedir().getabsolutepath(); mwebview.getsettings().setappcachepath(appcachepath); mwebview.getsettings().setallowfileaccess(true); mwebview.getsettings().setappcacheenabled(true); mwebview.getsettings().setcachemode(websettings.load_cache_only); mwebview.getsettings().setdefaultzoom(websettings.zoomdensity.far); mwebview.loadurl(args.getstring("url")); 

most modern browsers make request server, cached content, check if server has updated content available. in these cases, browser include "if-modified-since" header in request server can return empty http 304 response if nothing has changed.

your options either 1) configure server evaluate last-modified-since , return 304 appropriate. tell browser go ahead , use cached content. 2) implement page loading using javascript , create custom caching mechanism localstorage isn't subject whims of browser vendors. bit of work i've done on several performance-sensitive projects.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -