简体   繁体   English

使用持久存储创建HTML5离线应用

[英]Creating HTML5 offline app with perisistant storage

I have to create HTML5 application that downloads content when you have internet connection. 我必须创建HTML5应用程序,该应用程序可以在您连接互联网时下载内容。 After that you can loose connection and keep working on it. 之后,您可以松开连接并继续进行操作。 When connection is available agian it should synchornise all data with server. 当可用的连接可用时,应将所有数据与服务器同步。 It should persist data over restarting program/browser. 它应该在重新启动程序/浏览器时保留数据。 I think Slack and Visual Studio Code are written in this way. 我认为SlackVisual Studio Code是用这种方式编写的。

According to my research I have to use the Manifest file to download recourses and use File API 根据我的研究,我必须使用清单文件下载资源并使用File API

For now I found that Chrome devTools are best for this purpose. 目前,我发现Chrome devTools最适合此目的。

Have you other ideas how can I create such application? 您还有其他想法如何创建这样的应用程序吗? The important thing is it should be cross-platform . 重要的是它应该是跨平台的

Did you took a look at NW.js ? 您是否看过NW.js

It is a compact framework to build html applications, works on linux/win/OSX. 它是构建html应用程序的紧凑框架,可在linux / win / OSX上运行。

Here are some of my experiences working with this kind of apps: 这是我使用这类应用程序的一些经验:

  • To create a cross-platform HTML5 mobile App, you can use Apache Cordova . 要创建跨平台的HTML5移动应用程序,可以使用Apache Cordova There are a lot of pugins for cordova that have access to your device, eg the network-plugin that can read the connection type (wifi/cellular) or online-status. Cordova的许多插件都可以访问您的设备,例如可以读取连接类型(WiFi /蜂窝)或在线状态的网络插件。 Therefore this is certainly a better solution than a classic Website. 因此,与经典网站相比,这无疑是一个更好的解决方案。

  • In order to manage your Data on your application locally on the phone, you can use a single-page Javascript MVC-Framework. 为了在电话上本地管理应用程序上的数据,您可以使用单页Javascript MVC-Framework。 EmberJS together with Ember-Data has great features to manage models and model-relationships. EmberJS与Ember-Data一起具有管理模型和模型关系的强大功能。 There's a localStorage adapter that allows you to use HTML5 localStorage without any additional configuration. 有一个localStorage适配器,可让您无需任何其他配置即可使用HTML5 localStorage。 (There's even a ember-sync project that meets your requirements, but since it's in alpha phase you probably don't want to use it in production) (甚至有一个符合您要求的余烬同步项目,但是由于它处于Alpha阶段,您可能不想在生产中使用它)

  • as I said above, HTML5's localStorage is probably what you want to use to persist data on the user's phone. 就像我上面说的,HTML5的localStorage可能是您想要用来将数据保留在用户手机上的东西。 However, if your data gets too big for localStorage (~ >5MB) you can rely on cordova's SQLite-plugin. 但是,如果您的数据对于localStorage而言太大(〜> 5MB),则可以依靠cordova的SQLite插件。 You won't need to use the File-API by yourself at all. 您完全不需要自己使用File-API。

  • As you have pointed out, the chrome dev-tools are a great way for debugging your application. 正如您所指出的,chrome开发工具是调试应用程序的好方法。 They work flaweless for cordova web-views. 它们可以完美地实现Cordova网络视图。 Also, Safari has remote-debugging capabilities for iOS devices. 此外,Safari还为iOS设备提供了远程调试功能。 But the best thin is: You can write and debug most of your application in your browser since it is HTML/JS/CSS-based. 但是最好的办法是:由于它是基于HTML / JS / CSS的,因此您可以在浏览器中编写和调试大多数应用程序。 Ember has improved it's error handling tremendously over the last releases and with google chrome's extention ember-inspector also helps a lot in many cases. 在过去的版本中,Ember大大改进了它的错误处理能力,并且使用Google chrome的扩展Ember-inspector在许多情况下也有很大帮助。

In general, since cordova used to be painful sometimes, it came to an state here you can work with it in a very productive and efficient way. 通常,由于cordova有时会很痛苦,因此您可以以一种非常有效和高效的方式使用它。 The same goes for Ember and Ember-Data. Ember和Ember-Data也是如此。 Just give it a try. 试一试。 Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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