简体   繁体   中英

How to make website work in offline mode and save data

Creating a project with JS and .net. which needs to work even in offline mode. As I can see service worker can be used to cache static assets and can work offline, but we can't save data to Database. Please let me know if the service worker can save data also.

Is there any better approach to making the website work in offline mode and save data somewhere and pass it to the database when online? The saved data should not be cleared when the user closes the browser

In theory you can use a localstorage to permanently save data. I suggest that you do not save sensitive information within it or that could, in the wrong hands allow unwanted access to your services and create problems for you.

You can find information about how it works here. You will find simple examples for its full use.

https://it.javascript.info/localstorage

However, making an app work fully without an Internet connection can be complex and should be analyzed in each precise circumstance. Any change operations to the database could be parked in the localstorage and provide for a worker to make the calls when the network returns. It is not simple what you asked and I cannot help you further.

You also need to understand how to handle getting information from a Database if you have no connection. Some functionality will have to be suppressed while for "static" obtainments you might think about caching (as also said by you).

You can use localStorage to save data to the browser even when in offline mode.

See MDN reference

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM