The HTML5 offline cache was recently learned, but the server was seen to be configured. All of a sudden, after all, the server configuration is generally very complex, and node. JS Server is its own code generation, this is how to configure? Search on the internet for a long time, are useless about node. js and HTML5 offline cache, but Apache and so on a lot. After reading a PHP tutorial in NetEase Cloud class, I began to understand the principle of offline caching for HTML5 and successfully paired with node. js.
First, briefly describe the principle of HTML5 offline caching.
It is important that the browser makes a request to the server to obtain a file of mime-type text/cache-manifest, which is itself a static file, and that the file records which files the browser will cache.
At this time the first question came, manifest file content format how to write?
A: For a simple example, this example lists the files that the browser wants to cache.
CACHE MANIFEST
# CACHE MANIFEST is a must start
# cache: The file names to be cached are listed below
CACHE:
1.jpg
Solved the first question the second question came, how did HTML5 to ask for the paper?
For:
In the HTML tag in your HTML code, write this:
To give a simple example to deepen understanding: through the http://localhost/index.html access to the server root directory of the index.html file, the HTML code is as follows
1 <!DOCTYPE HTML>2 <HTMLManifest= "Test.manifest">3 <Head>4 <MetaCharSet= "Utf-8">5 <title></title>6 </Head>7 <Body>8 <imgsrc= "1.jpg" />9 </Body>Ten </HTML>
Test.manifest file contents As an example of the first question above;
When the browser renders to
By now, we still haven't talked about node. js. The server needs to be configured to support offline caching for servers such as Apache, what if it is node. js?
A: Let us first understand, Apache and other servers are to configure what the ghost thing. The above has said that the manifest file itself is a static file, get the manifest file and get the JPG file is actually one thing, but Apache and other servers are not all file formats are supported, in other words, your browser request JPG file is allowed, but, You request that the manifest file is not within the allowed range, so the configuration server specifies one more of the file types allowed by the server: the manifest type.
and for node. JS, whether it's jpg,png,manifest ... they're all files, and node. JS treats them all the same, and the only difference is their MIME type.
Therefore, for HTML5 offline caching, node. JS requires a configuration that adds support for manifest MIME types when writing a static file server.
If you use Express to configure the static file server, Express has helped you to increase the support of the manifest file. One word: cool!
node. js and HTML5 offline caching