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.
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.
Some benefits we can get from using 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.