You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I looked into it a little bit more.
if I understand everything correctly and did not forget any type of storage,
localStorage has a maximum of 10 MB per origin and
cookies have a maximum of 4 KB per domain and
indexDB can get quite big but is not persistent.
In my opinion this is not enough space to cache files.
But webbrowser cache files themselves quite good.
As a workaround I would propose, not caching files for web, but giving a warning and / or exception, which has to be dismissed.
Reacted by SimonIT, cielo, Raul Abreu, Tom Raganowicz and Shrijan Regmi
@connectety I'm not completely sure what you propose. Do you mean that if the platform is Web the library just uses NetworkImage instead of CachedImage? Devs will expect it to work differently.
I know, and this is not the best idea I have ever had.
I do not stand behind it completely, but I don't see any way to save content and a database, because the storage provided by web browsers is just too small.
Hopefully, I have forgotten some kind of storage.
And also I want to use this as a Hotfix, which can only be used after dismissing an exception or setting a flag or something. So that people will understand that it does not work as expected.
This idea should still somewhat work because there is already pretty good caching in the web and browsers.
Even if this objectively bad solution gets dismissed, I wanted to point out the Problem.
I started a fork (https://github.com/alextekartik/flutter_cache_manager and https://github.com/alextekartik/flutter_cached_network_image) where I experimented caching for the web by abstracting the file system (using fs_shim) and the storage (using idb_shim). It is definitely not perfect and a better solution could be found but I think having a way to abstract the database and file system into flutter_cache_manager could allow anyone to use their preferred storage (hive, moor, sqlite, indexed db....)
But with CORS and web browser already doing some caching, the web is a different experience that could require a specific and different network caching mechanism
This is what the web does really good out of the box. (In newer browser versions :D)
Also with the Cache API, you can save the most files with at least 50MB storage.
This might need some refactoring of this package to use sqflite for mobile and service workers for web (maybe using the plugin_platform_interface)
It doesn't cache on disk at the moment, but as @deakjahn asked it at least doesn't fail. It nicely returns the file which is just downloaded from the internet.
@IchordeDionysos I'm looking at the caching options for web. Thanks for the url
Actually, I store my files with the Cache API (not necessarily these ones but generally). Do you need some code so that you don't need to look it up yourself? Fairly straightforward.
I have an app-embedded platform plugin that simply offers a file storage interface for my app and gets translated to either plain old dart.io or Cache API, depending on the platform. It's tailored to my specific needs, so it's not perfect for immediate re-use without some tweaking. Basically, whenever the normal file IO speaks about folders, I use separate cache files on the web and treat a path like "foo/bar" as an item stored with the name "bar" inside a cache file named "foo". Nothing more nested than this, this was enough for my purposes.
But this supposes that you already have a JS file that you can put them into. If you don't, I can also show you how I normally attach one (very much like some of my plugins, eg. https://github.com/deakjahn/flutter_dropzone, but you don't need the added complexity of a platform view, of course). Basically, the few lines starting from here, called from whatever initialization function you have handy.
Yes, it shouldn't. Now I started to see something. I didn't open the whole package with AS or whatever IDE earlier because I didn't see the need. I just modified those three files in the flutter pub cache directory and compiled my test app (the test app was under the IDE, of course, just not your package).
If I open your package in the IDE, I get the same errors. However, if I just compile an app that uses your package, there are no errors at all, it compiles and runs. Go figure.
However, still with IOSink because that should be solved first. You can simply remove it from the IO but I don't know how you want to handle it on the Web.
This feature can now be easily implemented using pure Dart with no supporting JS code thanks to the recently released package:web. Here's a quick demo:
I haven't read the spec so I'm not sure if the .put() method guarantees that the call order will reflect the order in which the values will be persisted, but in case it does not guarantee that, then I suggest we use the synchronous local storage API as a mutex, this way we'll also be protected from simultaneous cross-tab writes.
Reacted by mono — Masayuki Ono and Mohammad Bagher Fakouri
Activity
renefloor commentedon Nov 1, 2019
The problem is not storing the files, but that it uses sqflite to store the cache info and that doesn't support Flutter Web yet: tekartik/sqflite#212
I'll look into this whether a switch to Moor or Hive https://github.com/renefloor/flutter_cache_manager/issues/121 is a good move. We'll have to migrate all the data, so I really have to study all the pros and cons before making a decision.
connectety commentedon Nov 2, 2019
I looked into it a little bit more.
if I understand everything correctly and did not forget any type of storage,
localStorage has a maximum of 10 MB per origin and
cookies have a maximum of 4 KB per domain and
indexDB can get quite big but is not persistent.
In my opinion this is not enough space to cache files.
But webbrowser cache files themselves quite good.
As a workaround I would propose, not caching files for web, but giving a warning and / or exception, which has to be dismissed.
renefloor commentedon Nov 4, 2019
@connectety I'm not completely sure what you propose. Do you mean that if the platform is Web the library just uses NetworkImage instead of CachedImage? Devs will expect it to work differently.
connectety commentedon Nov 5, 2019
Yes, for example.
I know, and this is not the best idea I have ever had.
I do not stand behind it completely, but I don't see any way to save content and a database, because the storage provided by web browsers is just too small.
Hopefully, I have forgotten some kind of storage.
And also I want to use this as a Hotfix, which can only be used after dismissing an exception or setting a flag or something. So that people will understand that it does not work as expected.
This idea should still somewhat work because there is already pretty good caching in the web and browsers.
Even if this objectively bad solution gets dismissed, I wanted to point out the Problem.
alextekartik commentedon Dec 23, 2019
I started a fork (https://github.com/alextekartik/flutter_cache_manager and https://github.com/alextekartik/flutter_cached_network_image) where I experimented caching for the web by abstracting the file system (using fs_shim) and the storage (using idb_shim). It is definitely not perfect and a better solution could be found but I think having a way to abstract the database and file system into flutter_cache_manager could allow anyone to use their preferred storage (hive, moor, sqlite, indexed db....)
But with CORS and web browser already doing some caching, the web is a different experience that could require a specific and different network caching mechanism
IchordeDionysos commentedon Feb 10, 2020
Why not use service workers for caching? 🤔
This is what the web does really good out of the box. (In newer browser versions :D)
Also with the Cache API, you can save the most files with at least 50MB storage.
This might need some refactoring of this package to use sqflite for mobile and service workers for web (maybe using the plugin_platform_interface)
Useful links:
https://developer.mozilla.org/en-US/docs/Web/API/Cache
deakjahn commentedon May 16, 2020
Until the support arrives, could it be made to fail silently? :-) Right now
never returns for me in a web app. Yes, it's easy to wrap it into an
if (!kIsWeb), just saying...renefloor commentedon Jun 20, 2020
It doesn't cache on disk at the moment, but as @deakjahn asked it at least doesn't fail. It nicely returns the file which is just downloaded from the internet.
@IchordeDionysos I'm looking at the caching options for web. Thanks for the url
deakjahn commentedon Jun 20, 2020
Actually, I store my files with the Cache API (not necessarily these ones but generally). Do you need some code so that you don't need to look it up yourself? Fairly straightforward.
renefloor commentedon Jun 20, 2020
Yes it is always good to see some code, but it looks really straight forward indeed.
The main challenge I think at the moment is adapting the cache manager to separate the current storage from the web api.
deakjahn commentedon Jun 20, 2020
I have an app-embedded platform plugin that simply offers a file storage interface for my app and gets translated to either plain old
dart.ioor Cache API, depending on the platform. It's tailored to my specific needs, so it's not perfect for immediate re-use without some tweaking. Basically, whenever the normal file IO speaks about folders, I use separate cache files on the web and treat a path like "foo/bar" as an item stored with the name "bar" inside a cache file named "foo". Nothing more nested than this, this was enough for my purposes.So, the interface itself is this:
Not that you would need all of them, especially not the ones that store a string (basically, a text file).
deakjahn commentedon Jun 20, 2020
The implementation is relatively simple:
with a simple helper:
deakjahn commentedon Jun 20, 2020
The native (JavaScript, that is) implementations are:
But this supposes that you already have a JS file that you can put them into. If you don't, I can also show you how I normally attach one (very much like some of my plugins, eg. https://github.com/deakjahn/flutter_dropzone, but you don't need the added complexity of a platform view, of course). Basically, the few lines starting from here, called from whatever initialization function you have handy.
deakjahn commentedon Jun 20, 2020
Oh yes, and of course, you need to make sure you have the support:
You do with any sane browser you might encounter today but still... :-)
renefloor commentedon Jun 20, 2020
If you use dart:html in a Flutter app, isn't this automatically added?
You basically take the content from the response and put them in a new response. Why wouldn't you just directly add the response from the server?
Yes of course, thanks for that as well. Especially for older iOS devices (iOS 10 and lower) this is important.
43 remaining items
deakjahn commentedon Jul 16, 2020
One problem at a time. :-))
What does this version do for you?
It still works over here.
renefloor commentedon Jul 16, 2020
I use Intellij, which is the same as Android Studio, but that shouldn't matter for the analysis.
deakjahn commentedon Jul 16, 2020
Yes, it shouldn't. Now I started to see something. I didn't open the whole package with AS or whatever IDE earlier because I didn't see the need. I just modified those three files in the flutter pub cache directory and compiled my test app (the test app was under the IDE, of course, just not your package).
If I open your package in the IDE, I get the same errors. However, if I just compile an app that uses your package, there are no errors at all, it compiles and runs. Go figure.
deakjahn commentedon Jul 16, 2020
I start to get the feeling that this is
pedanticstuff. :-)deakjahn commentedon Jul 16, 2020
Here we go: https://github.com/deakjahn/flutter_cache_manager/commit/66d74d2bc4bf8ebe0aff454cae616178f3ad6fff
deakjahn commentedon Jul 16, 2020
However, still with
IOSinkbecause that should be solved first. You can simply remove it from the IO but I don't know how you want to handle it on the Web.wer-mathurin commentedon Dec 1, 2020
Any status on this?
renefloor commentedon Dec 1, 2020
Not at the moment.
mrtdeh commentedon Jul 16, 2021
any update on this?
davemg3 commentedon Nov 21, 2021
Hello,
Is this still scheduled to add web support on flutter cache manager?
thks
tomekit commentedon Jan 29, 2023
I was wondering if there are still plans to add a Web support. It would greatly improve:
flutter_cached_network_imagecaching capabilities.duck-dev-go commentedon Nov 28, 2024
Any update on this?
kszczek commentedon May 31, 2025
This feature can now be easily implemented using pure Dart with no supporting JS code thanks to the recently released
package:web. Here's a quick demo:The Cache API allows us to store an enourmous amount of data (up to 60% of total disk space in Chrome and Safari!).
There is a small issue to think about though:
I haven't read the spec so I'm not sure if the
.put()method guarantees that the call order will reflect the order in which the values will be persisted, but in case it does not guarantee that, then I suggest we use the synchronous local storage API as a mutex, this way we'll also be protected from simultaneous cross-tab writes.nicolarigoni commentedon Mar 30, 2026
@ben-milanko hi, any update on this? Thanks
ben-milanko commentedon Mar 30, 2026
Hey @nicolarigoni ,
I've made a PR for this change #504
But looking at the repo the last update was 2024, so I'm not sure if this is still actively being maintained.
If you would like to use it, you can include the below in your pubspec yaml.