There is any method for webview cache Optimization in flutter? - flutter

I use flutter_inappwebview for fetching the website into the flutter app. I want to save all the resources like JS and CSS file content into the cache from website during webview start and then when I call same website the resources will intercept and inject the cached files into the webview. Is this possible.. If possible then how.. please explain with example. Thank you.

note: caching is already enabled for this plugin by default. but what you're asking is offline-mode which flutter_inappwebview plugin does not support yet.
the cache you're refering to is not the cache that browsers use (mobile or desktop) what you're refering to is basically called offline-mode in the world of browsers.
in regard to the flutter_inappwebview plugin there is already an issue (or two) about this feature you're looking for. and i believe it is not implemented yet.
you should keep an eye on these github issues issue-561 & issue-366

That flutter_inappwebview package has already a property, cacheEnabled with default parameter, true. You don't need to do anything about this. If you don't want to store cache files, then you can set it to false.
///Sets whether WebView should use browser caching. The default value is `true`.
///
///**NOTE**: available on iOS 9.0+.
bool cacheEnabled;
And, the clearCache property with the default value, 'false'.
///Set to `true` to have all the browser's cache cleared before the new WebView is opened. The default value is `false`.
bool clearCache;

Related

reuse result of initialize method from video_player flutter package

Is there option to reuse result of initialize method for video_player package? It takes time for complete - it would be great to cache it (eg. memory level) and reuse it when you back to before used video - and simple use cached data instead of wait for initialize result. I need it for intensive switching between videos.
There is a package called cached_video_player which may help resolve your problem. Check it out here.
I think you are asking about having the screen/page/widget pre-render. That is not currently supported by flutter according to this issue filed on github:
https://github.com/flutter/uxr/issues/6#issuecomment-881918751
Sure, but this is not very scalable and will quickly turn into a mess. It's much simpler and more flexible to just give MyRoute someway it can cache the next route, and then show that cached route when it needs. But flutter doesn't support this as everything needs to be 'on-stage' before it can be initialized. In AIR, or Unity, I could simply construct my new page, and it would begin loading data, I could then toss it on stage whenever I want.
PS. You probably already know you can pre-cache the video data/file itself.

How to access window.navigator.serial in flutter web

On some browsers there exists the the property serial on the window.navigator object.
I can see it on chrome but not on safari.
How can I access that object via dart in flutter web?
dart:html doesn't seem to include it. Is there a way to manually extend the window.navigator object to include it?
In the end I didn't access the window.navigator object from dart.
I access the serial and do all of the checks in javascript.
I use Js context to get data back from the Javascript.

Single page application cache issue

I have an single page application created in MVVM and knockout,typescript technology.
I am using knockout templating for creating different views within a Page.
The application Page has a view which shows a list of tasks user can start,pause,resume tasks.accordingly status changes using knockout.The database is getting updated but the UI doesnt reflect changes.
This application works fine in chrome but in IE the page doesn't get refreshed.In IE when from settings i choose request for new version of stored pages everytime.It works fine in IE also.
can any one help me out with a solution for this problem
It seems that your problem with the non-refreshing UI is a json caching problem.
Try to disable jquery ajax caching
$.ajaxSetup({ cache: false });
globally or just temporarily for the request which causes the problem.
IE is caching JSON responses, you wil find your response as a .json file in the temporary internet files folder :)
More information can be read here

chrome cache removal for single files

recently I had to remove my entire cache to be able to view a webpage I was working on. This is fine I guess but it could be improved by removing specific pages from the cache.
the chrome.browsingData.remove, seemingly has no option for indicating individual pages for removal. I was wondering if this could be done externally, but I am not familiar with the chromium code. I was also wondering if there are any planned changes to the chrome.browsingData.remove implementation.
Many thanks
To remove a single file cache enter its URL into browser and do hard refresh.
If you are working on a webpage and wish to avoid caching (btw, it's recommended! :) You can do it today in Chrome DevTools.
Go to Settings (the icon in the bottom-right corner) and click on it.
Then, you will have an option 'disable cache' - mark it and you done.
Just don't forget to return this state when you done working as chrome will be faster with its caching schema.
Edit 10/Feb/2022: Access the remote dev tools documentation for a whole suit of tools available to override cached files while developing:
https://developer.chrome.com/docs/devtools/storage/cache/
If you are attempting to clear HTTP cached data, which was the original question in the post, then the network log is where it is possible. the guide for that is here:
https://developer.chrome.com/docs/devtools/network/#load
First find the file then release its cacged content by right clicking:
https://developer.chrome.com/docs/devtools/network/reference/#clear-cache
To remove all files (not single files) while in Chrome DevTools you should click on the Dev Tools settings then choose
"Disable cache (while DevTools is open)". This was the first option on the page - it is now (as of Chrome 103 in 2022) under network in Preferences.
Note that these settings are not the main Chrome settings, but are specific to Dev Tools.
You can reach DevTools by pressing F12 while on a web page you want to debug or by pressing Ctrl-Shift-I.
Edited 28 July 2022
If you're building the page dynamically, then during development, you can put a random string at the end of the URL used to load the script.
<script src="path/to/script.js?_=<%=Math.random()%>"></script>
This will cause a cache miss for that file but will use the cache for everything else (subject to cache-control headers and so on). Just remember to remove the parameter before pushing to prod!
UPDATE : 2019, April 20
Lately, I'm working with Chrome browser's inbuilt feature - Overrides. With this feature, we can write code for HTML, CSS, JS, etc directly in the console and see it on the web-page.
Here's a tutorial that might be helpful
Previous Answer :
I'm working with Google Chrome extension Resource Override.
After installing this extension, I'm overriding the resource which I want from the server instead of cache:
STEP #2 : Override the resource which you want fresh from the server:
⭐Important Note - Access the plugin from the developer-console instead of the browser
⭐⭐ I started with this approach but have moved to approach suggested by Lukas Greblikas in the answer above.
Good Luck...

How to empty cache for WebView?

I have a Webview that must load an image! When I upload this image I see every time the same image as before, and i must reboot my app to see the new image...
I think is a cache problem..How can I solve that??
One quick and easy method would be to append the current time stamp onto the url whenever you load it.
So instead of loading:
http://www.myhost.com/myimg.jpg
you'd load
http://www.myhost.com/myimg.jpg?12345689
Using a cache breaker like this is a very common method in web development to force reloading of content.
I did do some quick googling and it appears clearing out NSURL's cache won't do the trick. In 10.6 the api reloadFromOrigin: may do the trick, but I'm not aware if this has made it's way onto the iphone yet.
Edit:
I found this page in the docs. It looks like you can use the preferences system to say whether or not to use caching. Not tested, but that'd be something to look at.