Adds a service-worker-update-notify
service and <ServiceWorkerUpdateNotify />
component which displays a reload link if the service-worker has found an update.
The component will show a message to the user when the availability of an updatehas been detected. Overwrite the default message using the component in block form:
The service allows you to react to an app update in a more programmatic manner, e.g.you could force reload the app. The service emits an update
event once an updatehas been detected. Here is an example of an application route that reloads the appautomatically:
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
export default class ApplicationRoute extends Route {
@service
serviceWorkerUpdateNotify;
beforeModel() {
this.serviceWorkerUpdateNotify.on('update', () => {
window.location.reload();
});
}
}
The poll interval can be configured in your config/environment.js
with:
module.exports = function(environment) {
let ENV = {
'ember-service-worker-update-notify': {
pollingInterval: 1200000 // Default is 20min
}
};
return ENV;
};
Testing this in your app should mainly be concerned with presenceand and what it looks like.
During testing, the polling will be disabled,and the reveal of the "New version available" contentis controlled by a promise set on the window
.In your tests, two helpers will aid you in assertingpresence and appearance: setupServiceWorkerUpdater
,and hasServiceWorkerUpdate
.
// ...
import {
setupServiceWorkerUpdater,
hasServiceWorkerUpdate
} from 'ember-service-worker-update-notify/test-support/updater';
module('Application | Index', function(hooks) {
setupApplicationTest(hooks);
setupServiceWorkerUpdater(hooks);
test('the update is shown', async function(assert) {
// assert that the content is not shown
await serviceWorkerUpdate();
// assert that the content is shown
});
});
yarn add --dev ember-concurrency # peer-dependency
yarn add --dev ember-service-worker-update-notify
git clone <repository-url>
this repositorycd ember-service-worker-update-notify
npm install
npm run lint:hbs
npm run lint:js
npm run lint:js -- --fix
ember test
– Runs the test suite on the current Ember versionember test --server
– Runs the test suite in "watch mode"ember try:each
– Runs the test suite against multiple Ember versionsember serve
For more information on using ember-cli, visit https://ember-cli.com/.
This project is licensed under the MIT License.
Ember Service Worker ember-service-worker is built and maintained by DockYard, contact us for expert Ember.js consulting. A pluggable approach to Service Workers for Ember.js Documentation Website Vis
Service Worker 是什么? service worker 是独立于当前页面的一段运行在浏览器后台进程里的脚本。 service worker不需要用户打开 web 页面,也不需要其他交互,异步地运行在一个完全独立的上下文环境,不会对主线程造成阻塞。基于service worker可以实现消息推送,静默更新以及地理围栏等服务。 service worker提供一种渐进增强的特性,使用特性
背景:如何让网页的用户体验做到极致 随着 Web 的快速发展,用户对站点的体验期望值越来越高,前端工程师有时候为了几十毫秒的速度优化而费劲心思,消耗大量时间。想要让自己的产品在无数产品中脱颖而出,就必须提升产品的性能和体验。在时间成本高昂的今天,响应速度的提升是开发者不得不面对的话题。 前端工程师有很多性能优化的手段,包括 CDN、CSS Sprite、文件的合并压缩、异步加载、资源缓存等等。其实
在开发 Service Worker 文件的过程中,如何调试呢?怎么才能确保线下开发的 Service Worker 文件在经过注册后到线上去运行是符合预期的呢?在这小节中将详细介绍如何调试 Service Worker。 Service Worker 作为独立于主线程的独立线程,在调试方面其实和常规的 JavaScript 开发类似,通常开发者关注的点大概有如下几点: Service Worke
通过前面对 Service Worker 概念的介绍,我们对 Service Worker 的一些概念和原理有了一定的了解,在本节将会重点介绍 Service Worker 注册的相关内容。主要会介绍如何为 Web App 注册一个 Service Worker、在不同的项目架构下注册 Service Worker 的方法、Service Worker 注册的一些细节和注意点等。 作用域 Serv
丢失网络连接是一个困扰 Web 用户多年的难题,即使是世界上最好的 Web App,如果因为网络原因访问不了它,那体验也是非常糟糕的。本小节要介绍的 Service Worker 能提供一种良好的统筹机制对资源缓存和网络请求进行缓存和处理,是 PWA 实现离线可访问、稳定访问、静态资源缓存的一项重要技术。 通常所讲的 Service Worker 指的是 Service Worker 线程。了解浏