“Why Facebook ditched the Mobile Web”
“Why LinkedIn dumped HTML5”
navigator.serviceWorker.register('/service-worker.js')
.then(function(registration) {
console.log('Registration successful', registration.scope);
})
.catch(function(error) {
console.log('Failed - service worker not installed', error);
});
// service-worker.js
self.addEventListener('install', function(event) {
// Awaiting clients using old SWs to be closed
});
self.addEventListener('activate', function(event) {
// Good time to clear out old caches.
});
self.addEventListener('fetch', function(event) {
// Intercepted a fetch!
event.respondWith(new Response('Hello world!'));
});
// App shell resources
var RESOURCES = [
'/js/app.js',
'/css/styles.css',
'/images/logo.png',
...
];
...
cache.addAll(RESOURCES);
self.addEventListener('fetch', function(event) {
var responsePromise = fetch(event.request)
.then(function(response) {
// Cache response if appropriate here...
return response;
})
.catch(function(err) {
// Fetch failed - maybe after a while!
return caches.match(event.request);
});
event.respondWith(responsePromise);
});
importScripts('/sw-toolbox/sw-toolbox.js');
toolbox.router.get('/images/*', toolbox.networkFirst, {
networkTimeoutSeconds: 10
});
toolbox.router.get('/images/*', toolbox.cacheFirst);
toolbox.router.get('/profile', toolbox.fastest);
navigator.bluetooth.requestDevice({
filters: [{
name: 'SomeAmazingRobot'
}],
optionalServices: ['battery_service']
})
...
...
.then(device => device.gatt.connect())
.then(server => server.getPrimaryService('battery_service'))
.then(service => service.getCharacteristic('battery_level'))
...
.then(characteristic => {
// Read battery level
return characteristic.readValue();
})
.then(value => {
var batteryLevel = value.getUint8(0);
console.log('Battery level', batteryLevel);
});
<script src="aframe.js"></script>
<a-scene>
<a-sphere position="0 1.25 -1" radius="1.25"
color="#EF2D5E"></a-sphere>
<a-box position="-1 0.5 1" rotation="0 45 0"
color="#4CC3D9"></a-box>
<a-cylinder position="1 0.75 1" radius="0.5"
color="#FFC65D"></a-cylinder>
<a-plane rotation="-90 0 0" width="4" height="4"
color="#7BC8A4"></a-plane>
<a-sky color="#ECECEC"></a-sky>
</a-scene>
new PaymentRequest(methodData, details)
.show()
.then(function(uiResult) {
processPayment(uiResult);
})
.catch(function(error) {
handlePaymentError(error);
});
// Register a one-off sync
navigator.serviceWorker.ready.then(function(swReg) {
return swReg.sync.register('myLovelySync');
});
// service-worker.js
self.addEventListener('sync', function(event) {
if (event.tag == 'myLovelySync') {
...
Link: </service-worker.js>; rel="serviceworker"
Origin-Trial: token_obtained_from_signup