Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sladage/dart-service-worker
Service Worker library for Dart.
https://github.com/sladage/dart-service-worker
Last synced: 20 days ago
JSON representation
Service Worker library for Dart.
- Host: GitHub
- URL: https://github.com/sladage/dart-service-worker
- Owner: sladage
- License: mit
- Created: 2016-07-25T14:53:24.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-09-09T16:03:17.000Z (about 8 years ago)
- Last Synced: 2024-07-30T18:14:16.602Z (4 months ago)
- Language: Dart
- Size: 33.2 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-dart - dart-service-worker - Service Worker library for Dart. (Libraries / Clint Library)
README
# Dart Service Worker library
Write Web Apps using Dart with Service Worker support. (Currently only supports compilation to javascript)
## Usage
Landing page:
```
import 'package:dart_service_worker/serviceworkermanager.dart' as SW;main() async {
try {
SW.ServiceWorker sw = await SW.serviceWorkerManager.register("sw.js");
print("registered");
sw.onMessage.listen((SW.MessageEvent e){
print(e.data);
});
} catch(e) {
print(e);
}
}
```Service worker:
```
void main() {
ServiceWorker sw = new ServiceWorker();
sw.onInstall.listen((e){
print("install");
//setup cache
});sw.onActivate.listen((e){
print("activate");
});sw.onMessage.listen((MessageEvent e){
print("msg:"+e.data);
});sw.onFetch.listen((FetchEvent e){
print("fetch");
e.respondWith(getReponse(e.request));
});
}Future getReponse(Request r) async {
Response response = await caches.match(r);
if (response != null) {
return response;
}
return fetch(request:r.clone());
}
```