I have created a library to start an activity with a Webview.
I'm trying to load local HTML file which with an Iframe inside it Whenever I'm starting the activity, for first time it is taking approx. of 5 seconds to display iframe. The 2nd time it is taking approx. of 2 seconds to display.
How can i reduce load time, for the first load?
Here are the two java files respectively.
WebviewOverlay.java
String botUrl = "someurl";
myWebView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
myWebView.loadUrl(botUrl);
return myWebView;
WebviewActivity.java
wb = new WebviewOverlay();
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().add(R.id.container, wb).commit();
This one is not anything to do with Android, web page has lot of data and or may be high resolution images which taking time or any scripts on the page which taking time while loading
You can use precaching to speed up the webpage load.
Load data(HTML) from the server and save it to a text file in our device memory.
Start a coroutine to load the webpage and store in local storage
Create a new activity in which we will create a webview which will be used to load this cached webpage.
Change some settings of our webview to enable support for javascript, domstorage, database etc.
Attach webclient to our webview
Load our previously created file which contains all our HTML cached and load it to the webview
Here's a Github repo that does exactly what you want it to do.
https://github.com/iambaljeet/WebViewPreCache
Try using optimized images in your Webpage. Resize it from mspaint
Related
So I am displaying video files from specific folder when the folder is selected but in the video list I am showing file name with the video thumbnail and that's where the problem starts i am using this way to get the thumb
Bitmap bmThumbnail = ThumbnailUtils.
extractThumbnail(ThumbnailUtils.createVideoThumbnail(info.getFilename(),
MediaStore.Video.Thumbnails.MINI_KIND), 60, 60);
if(bmThumbnail != null) {
imageView.setImageBitmap(bmThumbnail);}
and even if I don't set the bitmap or not the process is taking way too much time to open the new fragment whereas just displaying the name is smooth if I call the following bitmap it takes around 6-7 sec to display the list. The following thing are happening in the adapter as I test the app in adapter then recycler view
so I would like to know what is the best way to do it .
For using image loader i need the url which is not there as i am getting the album art using the file url but it will not produce the album art url directly.
Dealing with images and videos like that takes time. Particularly when dealing with a large group of them. It's unlikely you can speed up the operation but you can make it so your application doesn't have to wait for it by sending it to the background. I recommend Kotlin coroutines if you are up for converting to Kotlin. Otherwise I recommend making a thumbnail work manager
public class VideoThumbnailWorker extends Worker {
}
I want to save the webpages in sdcard when it loading in custom WebView and next time loading the same url I want to load it from cache and updates in the webpage should save in the cache.
Please try to use Asynchtask and download html file ,code right into doBackground method and set html in onPostExicute method.
When I try to reload the titanium webview true webview.reload(), the view does not reload correctly. Instead if loading the page it gives me a page not found.
what i'm doing:
In Titanium i make use of webviews to display data. These webviews make use of HTML that is stored in the local filesystem that Titanium offers. The webview is called url is set by :
webview.setUrl( Ti.Filesystem.applicationDataDirectory.toString() + 'index.html');
This sets the proper url for the webview, it let's me see the correct html page. When I use webview.reload(), it seems lost... is there a way to reload the webview, or should i remove and then add the webview again?
Setting a URL for WebView the resource is usually loaded from the Resources folder.
So try to move all HTML files there (into Resources, same folder where app.js is located) and simply use.
webview.setUrl('index.html');
This has worked for me both on iOS and Android.
(There is an issue related to Android regarding WebView and setting its content by html property but this shouldn't matter here)
I want to get images from the web page and save them into the local storage. I can find all image URLs from the HTML, load that images from the server and save them. But I don't want to access to the server second time for the same information which is already in webview. So I want to know how I can load images from the webview?
You can set a WebView cache in a few steps. Take a look below.
WebView webView = (WebView) findViewById(R.id.your_webView_Id);
String cacheDir = getDir("your_WV_cache_dir", Context.MODE_PRIVATE).getAbsolutePath();
webView.getSettings().setAppCacheMaxSize(1024 * 1024 * 1); // 1 Mb cache limited size > webView.getSettings().setAppCachePath(cacheDir);
webView.getSettings().setAppCacheEnabled(true);
webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); // This constant is important to you. This way you can load daa from cache, if it was already downloaded once.
You might take a look to th other possible values to the constant above at the WebView.WebSettings official documentation.
Let me know if it works.
I have a URL which I can load in webview. If I open the webview through browser it takes less time, but if I load the URL in webview it takes more time. Also if I have to reuse the same webview page with the same URL in another screen then I am unable to do that because if I use the same webview object in different screens then also it takes time to load the URL.
How do I make my webview to load a URL instantly?
You could use the YSlow or Google PageLoad plugins for your browser, to get specific tips on how to improve page load and speed up your page.
You could try a different cache mode: http://developer.android.com/reference/android/webkit/WebSettings.html#setCacheMode%28int%29
or, if the page doesn't change, just use loadDataWithBaseURL:
http://developer.android.com/reference/android/webkit/WebView.html#loadDataWithBaseURL%28java.lang.String,%20java.lang.String,%20java.lang.String,%20java.lang.String,%20java.lang.String%29
By default, a WebView provides no browser-like widgets, does not
enable JavaScript and web page errors are ignored.
here i paste small part of code of zirco-browser
settings.setJavaScriptEnabled(Controller.getInstance().getPreferences().getBoolean(Constants.PREFERENCES_BROWSER_ENABLE_JAVASCRIPT, true));
settings.setLoadsImagesAutomatically(Controller.getInstance().getPreferences().getBoolean(Constants.PREFERENCES_BROWSER_ENABLE_IMAGES, true));
settings.setUseWideViewPort(Controller.getInstance().getPreferences().getBoolean(Constants.PREFERENCES_BROWSER_USE_WIDE_VIEWPORT, true));
settings.setLoadWithOverviewMode(Controller.getInstance().getPreferences().getBoolean(Constants.PREFERENCES_BROWSER_LOAD_WITH_OVERVIEW, false));
settings.setSaveFormData(Controller.getInstance().getPreferences().getBoolean(Constants.PREFERENCES_BROWSER_ENABLE_FORM_DATA, true));
settings.setSavePassword(Controller.getInstance().getPreferences().getBoolean(Constants.PREFERENCES_BROWSER_ENABLE_PASSWORDS, true));
settings.setDefaultZoom(ZoomDensity.valueOf(Controller.getInstance().getPreferences().getString(Constants.PREFERENCES_DEFAULT_ZOOM_LEVEL, ZoomDensity.MEDIUM.toString())));
settings.setUserAgentString(Controller.getInstance().getPreferences().getString(Constants.PREFERENCES_BROWSER_USER_AGENT, Constants.USER_AGENT_DEFAULT));
set render priority high for your web view can solve problem up to some extent
its some thing like this
webview.getSettings().setRenderPriority(RenderPriority.HIGH);