FLUTTER ECOSYSTEM

isoos/service_worker

Dart용 서비스 워커 API

service_worker 프로젝트 이미지
Stars
37
Forks
18
최근 푸시(UTC)
2024. 4. 11.
프로젝트 상태
활성
István Soós GitHub avatar
GITHUB User

István Soós ↗

software engineer

@agilordBudapest, Hungary공식 웹사이트 ↗
언어DartHTMLCSS

이 저장소가 배포한 패키지

사용 중인 의존성

의존성 목록 2 개
  • js>=0.6.1 <2.0.0
  • lints개발 의존성^3.0.0

원본 README

아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.

README 펼치기 / 접기

Service Worker API for Dart

Dart-y wrappers for the ServiceWorker APIs.

Warning: the API is experimental, and subject to change.

Service Workers

A service worker is an event-driven worker registered against an origin and a path. It takes the form of a JavaScript file that can control the web page/site it is associated with, intercepting and modifying navigation and resource requests, and caching resources in a very granular fashion to give you complete control over how your app behaves in certain situations (the most obvious one being when the network is not available.)

A service worker is run in a worker context: it therefore has no DOM access, and runs on a different thread to the main JavaScript that powers your app, so it is not blocking. It is designed to be fully async; as a consequence, APIs such as synchronous XHR and localStorage can't be used inside a service worker.

Quickstart

Register the Service Worker from your application script, like in example/web/main.dart:

import 'package:service_worker/window.dart' as sw;

void main() {
  if (sw.isSupported) {
    sw.register('sw.dart.js');
  } else {
    print('ServiceWorkers are not supported.');
  }
}

Write the Service Worker in a separate script, like in example/web/sw.dart:

import 'package:service_worker/service_worker.dart';

void main(List<String> args) {
  onInstall.listen((event) {
    print('ServiceWorker installed.');
  });
}

Limitation

You need to force dart2js compilation for service worker to work during debug mode. See build.yaml in the example folder.