Mulham Aryan Mulham Aryan - 1 year ago 412
Java Question

android webview loadurl slow

I am working on an application where i am loading a webpage from a an external url in a webview.
Loading the page take so much time to be loaded it take between 30 Seconds and 1 Minute
so please take look here on my code

import android.os.Bundle;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;

public class WebActivity extends AppCompatActivity {

private WebView webView;
private ProgressBar progressBar;
protected void onCreate(Bundle savedInstanceState) {
Toolbar toolbar = (Toolbar) findViewById(;

webView = (WebView)findViewById(;
progressBar= (ProgressBar)findViewById(;
String link = getIntent().getExtras().getString("webLink");
String title = getIntent().getExtras().getString("webTitle");
Log.d("WEB", link);
webView.setWebViewClient(new MyBrowser());


public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// app icon in action bar clicked; goto parent activity.
return true;
return super.onOptionsItemSelected(item);

public class MyBrowser extends WebViewClient {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return super.shouldOverrideUrlLoading(view, url);

public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);


any idea to improve the performance ?

Answer Source

Unofortunately, there won't be much you can do to fix this. However:

  • Try to load your URL in the browser on your android device. Is it faster ? If not, there's not really much you can do.

There's a couple of things you can try though, and a few things to check. Specifically:

  • You're setting the visibility to View.GONE (making your webview invisible) while the page is loading, and then making it visible again when the page has loaded. This is probably the problem.

    Try without this, and you will probably find that it will be quicker. In my experience, onPageFinished(..) only fires some time after the page is loaded.

  • Does the page really require JavaScript ? If not, don't enable it.

  • If it's feaseable in your case, you can use a HTML parser like Jsoup to extract only the desired data from the page, and show that to the user. This will be a lot faster.

    If the page uses Ajax to load data dynamically, you can also load the data directly from the endpoints it uses. Open the page in a desktop browser, and open the network tab of developer tools to find out how the page works and loads data.

  • You can block requests from the WebView with shouldInterceptRequest(..). This may help if the page has things like eg. Facebook share buttons or extra images which you don't need. Blocking these will speed up load times.

If you show us the URL you're using, maybe I can investigate more and tell you axactly how you could speed it up in your case. Let me know if it helps.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download