zoukankan      html  css  js  c++  java
  • H5学习笔记-应用缓存,Web worker,服务器发送事件

    亮了

    应用缓存用法

    <!DOCTYPE HTML>
    <html manifest="demo.appcache">
    
    <body>
    The content of the document......
    </body>
    
    </html>

    Manifest文件

    CACHE MANIFEST
    # 2012-02-21 v1.0.0
    /theme.css
    /logo.gif
    /main.js
    
    NETWORK:
    login.asp
    
    FALLBACK:
    /html5/ /404.html

    Web Workers

     独立于其他脚本,不会影响页面的性能,后台单独运行

    <!DOCTYPE html>
    <html>
    <body>
    
    <p>计数: <output id="result"></output></p>
    <button onclick="startWorker()">开始 Worker</button> 
    <button onclick="stopWorker()">停止 Worker</button>
    <br /><br />
    
    <script>
    var w;
    
    function startWorker()
    {
    if(typeof(Worker)!=="undefined")
      {
      if(typeof(w)=="undefined")
      {
      w=new Worker("/example/html5/demo_workers.js");
      }
      w.onmessage = function (event) {
        document.getElementById("result").innerHTML=event.data;
        };
      }
    else
      {
      document.getElementById("result").innerHTML="Sorry, your browser does not support Web Workers...";
      }
    }
    
    function stopWorker()
    { 
    w.terminate();
    }
    </script>
    
    </body>
    </html>
    var i=0;
    
    function timedCount()
    {
    i=i+1;
    postMessage(i);
    setTimeout("timedCount()",500);
    }
    
    timedCount();
    事件描述
    onopen 当通往服务器的连接被打开
    onmessage 当接收到消息
    onerror 当错误发生
  • 相关阅读:
    链接工作过程
    编译器工作过程
    图像边缘提取
    剑指32-1 从上到下打印二叉树
    剑指31 栈的压入 弹出序列
    剑指30 包含min函数的栈
    剑指28 对称的二叉树(暂留)
    asp.net core获取当前请求的完整url
    安装启动consul代理,consul后台管理
    asp.net core用命令方式启动项目
  • 原文地址:https://www.cnblogs.com/markleilei/p/6019191.html
Copyright © 2011-2022 走看看