Is it possible to cache about 1 GB in the browser?

  • 0
    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?
    I'm primarily interested in chrome and safari, including smartphones.
    JavaScript Anonymous, Jun 13, 2019

  • 3 Answers
  • 0
    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:

    <script src="https://cdnjs.cloudflare.com/ajax/libs/localforage/1.9.0/localforage.js"></script>


    Next, to save some data, we execute in the browser console:

    result = await localforage.setItem('key', save_data);
    console.log('Данные успешно сохранены:');
    console.dir(result);


    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('Данные успешно извлечены:');
    console.dir(result);


    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

  • 0
    No (5-10 MB maximum), and it sounds silly. What will users with limited resources do?
    Anonymous

  • 0
    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 limits
    Matthew Roberts

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!