1

I am implementing Android webview which loads lists of feeds. When the internet is off, webview loads from cached data, sometimes it loads perfectly but sometimes it goes blank, this pattern occurs alternately.

When I checked resources loaded (i.e urls) using onLoadResource() method of webviewclient, I found that all the resources ain't getting loaded when blank page is displayed

Logs when webview loads properly

2019-08-08 11:19:38.039 23385-23385/com.share D/WebFeedFragment: onPageStarted, loadedUrl: http://example.com/posts
2019-08-08 11:19:38.040 23385-23385/com.share I/WebFeedFragment: onLoadResource: http://example.com/posts
2019-08-08 11:19:38.096 23385-23385/com.share I/WebFeedFragment: onLoadResource: https://fonts.googleapis.com/cssfamily=Lato:400,700&display=swap
2019-08-08 11:19:38.097 23385-23385/com.share I/WebFeedFragment: onLoadResource: http://example.com/static/css/2.0b833ac8.chunk.css
2019-08-08 11:19:38.100 23385-23385/com.share I/WebFeedFragment: onLoadResource: http://example.com/static/css/main.2f5f4111.chunk.css
2019-08-08 11:19:38.103 23385-23385/com.share I/WebFeedFragment: onLoadResource: http://example.com/static/js/2.aaef6f1d.chunk.js
2019-08-08 11:19:38.105 23385-23385/com.share I/WebFeedFragment: onLoadResource: http://example.com/static/js/main.583be9bf.chunk.js
2019-08-08 11:19:38.648 23385-23385/com.share I/WebFeedFragment: onLoadResource: http://example.com/web/v1/webposts
2019-08-08 11:19:38.659 23385-23385/com.share I/WebFeedFragment: onPageFinished: http://example.com/posts
2019-08-08 11:19:38.759 23385-23385/com.share I/WebFeedFragment: onLoadResource: http://example.com/static/media/share_icon.591a6a61.svg
2019-08-08 11:19:38.759 23385-23385/com.share I/WebFeedFragment: onLoadResource: http://example.com/static/media/share_icon.5918n61.svg
2019-08-08 11:19:38.764 23385-23385/com.share I/WebFeedFragment: onLoadResource: https://s3.ap-1.amazonaws.com/app-media-files/photos/None/FeedIMage_tiny.jpg
2019-08-08 11:19:38.764 23385-23385/com.share I/WebFeedFragment: onLoadResource: https://s3.ap-1.amazonaws.com/app-media-files/photos/None/Free_tiny.jpg
2019-08-08 11:19:38.768 23385-23385/com.share I/WebFeedFragment: onLoadResource: http://example.com/companylogo.png

Logs when blank page is displayed on webview

2019-08-08 11:17:55.582 23385-23385/com.share D/WebFeedFragment: onPageStarted, loadedUrl: http://example.com/posts
2019-08-08 11:17:55.585 23385-23385/com.share I/WebFeedFragment: onLoadResource: http://example.com/posts
2019-08-08 11:17:55.682 23385-23385/com.share I/WebFeedFragment: onLoadResource:http://example.com/static/css/2.0b833ac8.chunk.css
2019-08-08 11:17:55.683 23385-23385/com.share I/WebFeedFragment: onLoadResource: http://example.com/static/css/main.2f5f4111.chunk.css
2019-08-08 11:17:55.690 23385-23385/com.share I/WebFeedFragment: onLoadResource: http://example.com/static/js/2.aaef6f1d.chunk.js
2019-08-08 11:17:55.691 23385-23385/com.share I/WebFeedFragment: onLoadResource: http://example.com/static/js/main.583be9bf.chunk.js  
2019-08-08 11:17:55.728 23385-23385/com.share I/WebFeedFragment: onPageFinished: http://example.com/posts
2019-08-08 11:17:55.748 23385-23385/com.share I/WebFeedFragment: onLoadResource: http://example.com/companylogo.png

I expect all the cached resources to be loaded everytime. I am setting webview cache mode to LOAD_DEFAULT when internet is available and LOAD_CACHE_ONLY when it's not

  • See this answer, https://stackoverflow.com/a/17429301/3948854. Loading image from the cache should be handled in the website itself. – Rishabh Sagar Aug 08 '19 at 06:54

0 Answers0