Is it possible to cache about 1 GB in the browser?
We are planning to write a specific web application. The main requirement is that the user can work with the data package regardless of the speed of the Internet connection, including offline. "Data package" is about 300-400 megabytes (the speed of work with it is decent even on weak devices). There are no resources for writing applications for different platforms.
Is it possible to store this amount of data in modern browsers and what is the best way to do it?
Perhaps, of course. To store large amounts of data in browsers, there is a built-in database IndexedDB .
To work with it, first, we include a special library that simplifies input and output:
Next, to save some data, we execute in the browser console:
result = await localforage.setItem('key', save_data);
console.log('Данные успешно сохранены:');
Where in save_data is the saved data, and key is the key by which you could get access to them.
Of the features, in save_data we can put any data type - even a string, even an array, even an object. You can even save the file if you want! At the same time, there are no restrictions on the amount of stored data, you can at least one hundred megabytes, at least three hundred megabytes - the built-in storage will gobble up everything.
To later retrieve the saved data, just execute:
result = await localforage.getItem('key');
console.log('Данные успешно извлечены:');
Data storage period is unlimited. Or until the user manually resets the browser cache.
P. S. Please note that if you use the word await somewhere in your code inside a function, then such a function must have the async prefix! Otherwise, you will get an error. In the console, you can use await in the forehead, but to use await in the code, you need the function inside which it is called to be asynchronous !!!Anonymous
No (5-10 MB maximum), and it sounds silly. What will users with limited resources do?Anonymous
https://developer.mozilla.org/en-US/docs / Web / API / I ... Download everything locally and run some kind of electron. Ps gig in cache is tough! In theory, see the limitsMatthew Roberts
To place the code, please use CodePen or similar tool. Thanks you!