admin 管理员组

文章数量: 887016

小马快跑win7激活

Service workers are great for many purposes:  speed, offline, cache control, and more.  You can view many code service worker usage samples over at the Service Worker Cookbook, if you're so interested.  One of those recipes, Immediate Claim, is as important and useful as it provides a way to claim your service worker more quickly, meaning you can receive fetch events faster.

服务工作者在许多方面都很出色:速度,脱机,缓存控制等等。 如果您对此感兴趣,可以在Service Worker Cookbook上查看许多代码Service Worker用法示例。 这些配方之一,即即时索赔 ,同等重要和有用,因为它提供了一种更快地要求服务人员索赔的方法,这意味着您可以更快地接收提取事件。

You can liken the following code quickening to DOMContentLoaded (commonly known as domready) vs. the old load event -- set processing into motion more quickly.  The trick involves the service worker's install and activate events:

您可以将以下代码比喻为DOMContentLoaded (通常称为domready )和旧的load事件,从而使处理更快地运动。 技巧涉及服务人员的installactivate事件:


// Install event - cache files (...or not)
// Be sure to call skipWaiting()!
self.addEventListener('install', function(event) {
  event.waitUntil(
	caches.open('my-cache').then(function(cache) {
        // Important to `return` the promise here to have `skipWaiting()`
        // fire after the cache has been updated.
        return cache.addAll([/* file1.jpg, file2.png, ... */]);
    }).then(function() {
      // `skipWaiting()` forces the waiting ServiceWorker to become the
      // active ServiceWorker, triggering the `onactivate` event.
      // Together with `Clients.claim()` this allows a worker to take effect
      // immediately in the client(s).
      return self.skipWaiting();
    })
  );
});

// Activate event
// Be sure to call self.clients.claim()
self.addEventListener('activate', function(event) {
	// `claim()` sets this worker as the active worker for all clients that
	// match the workers scope and triggers an `oncontrollerchange` event for
	// the clients.
	return self.clients.claim();
});


Ultimately returning the skipWaiting() from the install event triggers the activate event, activating the service worker immediately and allowing your service worker to work with fetch events and other service worker capabilities.  Service workers require a navigation event (reloading the page, going to a new page, etc.) to activate which is why this trick is so handy.

最终返回skipWaiting()install事件触发activate ,请立即激活该服务的工人,并让您的服务人员来工作, fetch事件和其他服务人员的能力。 服务人员需要导航事件(重新加载页面,进入新页面等)才能激活,这就是为什么这一技巧很方便的原因。

Look forward to more service worker tips and examples on the blog over the coming months!

希望在接下来的几个月中在博客上提供更多服务工作者的提示和示例!

翻译自: https://davidwalsh.name/service-worker-claim

小马快跑win7激活

本文标签: 更快 小马 快跑 人员