varCACHE_NAME='my-web-app-cache';varurlsToCache = ['/','/styles/main.css','/scripts/app.js','/scripts/lib.js']; self.addEventListener('install',function(event) {// event.waitUntil 使用 promise 来获得安装时长及安装是否失败event.waitUntil( caches.open(CACHE_NAME) .then(function(cache)...
为了在网络应用中使用 Service Worker,首先得在 JavaScript 代码中对其进行注册。当 Service Worker 注册的时候,它会让浏览器在后台开始安装 Service Worker 的步骤。 通过注册 Service Worker,浏览器知晓包含 Service Worker 相关代码的 JavaScript 文件。看下如下代码: if ('serviceWorker' in navigator) { window.ad...
当你意识到 JavaScript 是一门没有定义线程模型的语言的时候,或许你会感觉非常的惊讶。Web Workers 并不是 JavaScript 的一部分,他们是可以通过 JavaScript 进行操作的浏览器功能之一。以前,大多数的浏览器是单线程的(当然,现在已经变了),而且大多数的 JavaScript 功能是在浏览器端实现完成的。Node.js 没有实现 Web...
That’s where the catch() method comes in. You can state multiple then() statements inside a promise. This is called promise chaining. Let’s use an example to illustrate how chaining works: returnName.then(data => { console.log(data); }).then(() => { console.log("This function ...
个人总结: 1.介绍了网页消息推送通知机制 全文地址:https://github.com/Troland/how-javascript-works 这是 JavaScript 工作原理的第九章。 现在让我们把注意力转移到网页推送通知:我们将会查看其构造,探索发送/接收通知背后的过程以及最后分享一下
promise type is and how is it written syntactically. Also have seen the various Promise parameters required and their usage in real coding scenarios. We have shown a few examples from a simple one to one complex example, which will help get a good idea of how Promise works for Asynchronous...
Introduced in ES11, you can use the Promise.allSettled() method, which waits for all promises to settle — i.e. it waits till all the given promises are either fulfilled or rejected. Upon completion, it returns a single Pr
promise .then(res => {console.log(res)}) .catch(err => {console.log(err)}) .finally(() => console.log('You have reached the end of execution!')) Console output: Chaining is another best feature of Promises in JavaScript. Instead of bundling all dependencies into a single code block...
Theasyncandawaitkeywords enable asynchronous, promise-based behavior in a cleaner style. Let’s understand howasync/awaitworks. The function we are waiting for should return an instance of Promise class to wait for it to execute using the await keyword before calling it. As mentioned above, the...
in the use of prerender-spa-plugin. The content of this chapter is a supplement and expansion to the previous article. It introduces in detail how the plug-in mechanism of Webpack works, and it is simple to write before. What is the principle of the effective replacement of the plug-in...