Inline Workers--Web workers without a separate Javascript file

Posted zyip

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Inline Workers--Web workers without a separate Javascript file相关的知识,希望对你有一定的参考价值。

 

 

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8" />
</head>
<body>

  <div id="log"></div>

  <script id="worker1" type="javascript/worker">
    // This script won‘t be parsed by JS engines because its type is javascript/worker.
    self.onmessage = function(e) {
      self.postMessage(msg from worker);
    };
    // Rest of your worker code goes here.
  </script>

  <script>
    function log(msg) {
      // Use a fragment: browser will only render/reflow once.
      var fragment = document.createDocumentFragment();
      fragment.appendChild(document.createTextNode(msg));
      fragment.appendChild(document.createElement(br));

      document.querySelector("#log").appendChild(fragment);
    }

    var blob = new Blob([
      document.querySelector(#worker1).textContent
    ], { type: "text/javascript" })

    // Note: window.webkitURL.createObjectURL() in Chrome 10+.
    var worker = new Worker(window.URL.createObjectURL(blob));
    worker.onmessage = function(e) {
      log("Received: " + e.data);
    }
    worker.postMessage("hello"); // Start the worker.
  </script>
</body>
</html>

 

 

https://www.html5rocks.com/en/tutorials/workers/basics/#toc-inlineworkers

 

以上是关于Inline Workers--Web workers without a separate Javascript file的主要内容,如果未能解决你的问题,请参考以下文章

display:inline-block not working outlook / gmail

[翻译]Service workers:PWA背后的英雄

微信小程序-超出部分显示省略号(单行与多行)

微信小程序-超出部分显示省略号(单行与多行)

vue 热更新内存溢出

无法让 CSS 悬停动画工作