Answer the question
In order to leave comments, you need to log in
Is it possible to cache about 1 GB in the browser?
I plan to write a specific web application. The main requirement is that the user be able to work with the data package regardless of the speed of the Internet connection, including offline. A "data package" is about 300-400 megabytes (the speed of working with it is decent even on weak devices). There are no resources for writing applications for different platforms.
Is it possible to save this amount of data in modern browsers and what is the best way to do it?
Interested primarily in chrome and safari, including on smartphones.
Answer the question
In order to leave comments, you need to log in
Perhaps of course. To store large amounts of data in browsers, there is a built-in IndexedDB database .
To work with it, we first connect a special library that simplifies input and output:
<script src="https://cdnjs.cloudflare.com/ajax/libs/localforage/1.9.0/localforage.js"></script>
result = await localforage.setItem('key', save_data);
console.log('Данные успешно сохранены:');
console.dir(result);
result = await localforage.getItem('key');
console.log('Данные успешно извлечены:');
console.dir(result);
No (5-10 MB maximum), and it sounds stupid. What will users with limited resources do?
https://developer.mozilla.org/en-US/docs/Web/API/I... Download everything locally and run some electron. Ps gig in cache is tough! Look at the limits
If you don't need extra libraries, here is my simplified version
let db={
o:h=>new Promise(r=>{let i=indexedDB.open('you_db');i.onsuccess=()=>r(i.result);i.onupgradeneeded=()=>i.result.createObjectStore('db',{keyPath:'key'})}).then(h),
t:o=>o.transaction('db','readwrite').objectStore('db'),
g:(k,h)=>db.o(o=>new Promise(r=>{let t=db.t(o).get(k);t.onsuccess=()=>r(t.result&&t.result.val)}).then(h)),
s:(k,v)=>db.o(o=>db.t(o).put({key:k,val:v}))
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question