Nebula

Offline Package

A offline package is a signed archive file that consists of HTML resources and Javascript for H5 Container to render and display in WebView. There are two types of offline packages, global package which contains common resources that can be shared among applications, and private package which contains only the application specific resources.

offline-package-structure

The local content inside the offline package shares the same URL as the remote content, when H5 Container requests for resource by specifying the resource URL, the H5 Container will intercepts the request URL and check if this URL can be served from the local offline package, if there is a match, the local resource will be delivered to H5 Container, otherwise H5 Container will grab the remote content over HTTP transport. Therefore, no matter whether it is a local or remote copy, the source of the HTML resource is totally transparent to the WebView.

A offline package will eventually be downloaded to device storage and loaded into application memory space when necessary. Please note that the a signature verification on the offline package file is performed before loading it into memory, and we do not extract the archive to avoid performing tedious and time consuming signature verification for each individual extracted files. Once the signature verification passes, the content of offline package is stored in memory as a Map, with the resource URL as key and content byte array as value.

offline-package-in-memory

Some benefits we can get from using offline package

  • We can ship the initial offline package together with the application, so the application does not need to download the remote content when user launch the application at the very first time. Therefore the resources are immediately ready for render and it delivers a great user experience.
  • We can also push a new version of offline package as a hot-fix or update to the application without going through the app store publish and review procedure, it is very useful in mission critical crash fixes.

The Usage of offline package

offline-package

As illustrated in the activity diagram, H5 Container will first load the public offline package and then private offline packages if any. If the offline package is invalid (i.e., signature verification failed) or the requested content is not available in the offline package, the H5 Container will request remote content as a fallback. And finally the content will be passed to WebView for rendering.