application cache 应用缓存

这些应用还是要自己实现一遍,否则真不知道哪里会出问题。

客户端:

<!DOCTYPE html>
<html manifest = 'demo.appcache'>
    <head>
        <title>H5 application cache</title> 
        <Meta http-equiv="Content-Type" Content="text/cache-manifest">
        <link href="stylesheets/style.css" rel="stylesheet">       
    </head>
    <body>
        <pre id='result'>
            result
        </pre>  
        <img src='images/1.jpg'></img>           
        <img src='images/2.jpg'></img>           
    </body>
    <script type="text/javascript">       
    
    </script>
</html>

demo.appcache:

CACHE MANIFEST                       //后面没有:,
../stylesheets/style.css
../images/1.jpg

NETWORK:
../images/2.jpg

FALLBACK:

我使用node做后端的,直接在.html中修改Content-Type为text/cache-manifest;在手机上看到了效果,1.jpg是缓存的,2.jpg是需要网络连接的,在手机断开WiFi的情况下,refresh页面,仍可看到1.jpg。

 

原文地址:https://www.cnblogs.com/wang-jing/p/4094570.html