Skip to content

Commit 2ae41ee

Browse files
author
T2
committed
translate(content): service-worker-getting-started.md
1 parent db17a88 commit 2ae41ee

File tree

1 file changed

+75
-82
lines changed

1 file changed

+75
-82
lines changed
Lines changed: 75 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,203 +1,196 @@
1-
# Getting Started with Service Workers
1+
# Service Workerを始める
22

3-
#### Prerequisites
3+
#### 前提条件
44

5-
A basic understanding of the following:
6-
* [Introduction to Angular service workers](guide/service-worker-intro).
5+
次の基本的理解があること
6+
* [Angular Service Worker イントロダクション](guide/service-worker-intro)
77

88
<hr />
99

1010

11-
Beginning in Angular 5.0.0, you can easily enable Angular service worker support in any CLI project. This document explains how to enable Angular service worker support in new and existing projects. It then uses a simple example to show you a service worker in action, demonstrating loading and basic caching.
11+
Angular 5.0.0から、どのCLIプロジェクトでもAngular Service Workerのサポートを簡単に有効にすることができます。このドキュメントでは、新規および既存のプロジェクトでAngular Service Workerのサポートを有効にする方法について説明します。次に、単純な例を使用して、Service Workerが実際に動作していることを確認し、読み込みとキャッシングの基本をデモで行います。
1212

13-
## Adding a service worker to a new application
13+
## 新しいアプリケーションにService Workerを追加する
1414

15-
If you're generating a new CLI project, you can use the CLI to set up the Angular service worker as part of creating the project. To do so, add the `--service-worker` flag to the `ng new` command:
15+
新しくCLIプロジェクトを作る場合は、CLIを使用して、プロジェクト作成の一環としてAngular Service Workerを設定できます。これを行うには、`--service-worker`フラグを`ng new`コマンドに追加します。
1616

1717
```sh
1818
ng new my-project --service-worker
1919
```
2020

21-
The `--service-worker` flag takes care of configuring your app to
22-
use service workers by adding the `service-worker` package along
23-
with setting up the necessary files to support service workers.
24-
For information on the details, see the following section
25-
which covers the process in detail as it shows you how to add a
26-
service worker manually to an existing app.
21+
`--service-worker`フラグにより、`service-worker`パッケージを追加して、Service Workerを使うために必要なファイルをアプリケーションに設定します。詳細については、次のセクションを参照してください。Service Workerを既存のアプリに手動で追加するために、プロセスを詳しく説明しています。
2722

2823

2924

30-
## Adding a service worker to an existing app
25+
## 既存のアプリケーションにService Workerを追加する
3126

32-
To add a service worker to an existing app:
27+
既存のアプリケーションにService Workerを追加するためには、次のステップになります。
3328

34-
1. Add the service worker package.
35-
2. Enable service worker build support in the CLI.
36-
3. Import and register the service worker.
37-
4. Create the service worker configuration file, which specifies the caching behaviors and other settings.
38-
5. Build the project.
29+
1. Service Workerのパッケージを追加します。
30+
2. CLIでService Workerのビルドサポートを有効にします。
31+
3. Service Workerをインポートして登録します。
32+
4. キャッシングビヘイビアなどの設定を指定するService Workerの設定ファイルを作成します。
33+
5. プロジェクトをビルドします。
3934

40-
### Step 1: Add the service worker package
35+
### ステップ1: Service Workerのパッケージを追加します
4136

42-
Add the package `@angular/service-worker`, using the yarn utility as shown here:
37+
次のように、yarnを使用して、`@angular/service-worker`パッケージを追加してください。
4338

4439
```sh
4540
yarn add @angular/service-worker
4641
```
4742

48-
### Step 2: Enable service worker build support in the CLI
43+
### ステップ2: CLIでService Workerのビルドサポートを有効にします
4944

50-
To enable the Angular service worker, the CLI must generate an Angular service worker manifest at build time. To cause the CLI to generate the manifest for an existing project, set the `serviceWorker` flag to `true` in the project's `.angular-cli.json` file as shown here:
45+
AngularにおけるService Workerを有効にするために、CLIはビルド時にAngular Service Workerマニフェストを生成する必要があります。CLIが既存のプロジェクトでマニフェストを生成するようにするためには、プロジェクトの`.angular-cli.json`ファイルで`serviceWorker`フラグを`true`に設定します。
5146

5247
```sh
5348
ng set apps.0.serviceWorker=true
5449
```
5550

56-
### Step 3: Import and register the service worker
51+
### ステップ3: Service Workerをインポートして登録します
5752

58-
To import and register the Angular service worker:
53+
AngularにおけるService Workerをインポートして登録するために
5954

60-
At the top of the root module, `src/app/app.module.ts`, import `ServiceWorkerModule` and `environment`.
55+
ルートモジュール`src/app/app.module.ts`のトップで、`ServiceWorkerModule``environment`をインポートしてください。
6156

6257
<code-example path="service-worker-getting-started/src/app/app.module.ts" linenums="false" title="src/app/app.module.ts" region="sw-import"> </code-example>
6358

6459

65-
Add `ServiceWorkerModule` to the `@NgModule` `imports` array. Use the `register()` helper to take care of registering the service worker, taking care to disable the service worker when not running in production mode.
60+
`ServiceWorkerModule``@NgModule``imports`配列に追加してください。プロダクションモードで実行していないときに、Service Workerを無効にするように登録するためには、`register()`ヘルパーを使用してください。
6661

6762
<code-example path="service-worker-getting-started/src/app/app.module.ts" linenums="false" title="src/app/app.module.ts" region="sw-module"> </code-example>
6863

69-
The file `ngsw-worker.js` is the name of the prebuilt service worker script, which the CLI copies into `dist/` to deploy along with your server.
64+
`ngsw-worker.js`ファイルは、CLIがあなたのサーバーに一緒にデプロイするために`dist/`にコピーする、事前構築されたService Workerのスクリプト名称です。
7065

71-
### Step 4: Create the configuration file, `ngsw-config.json`
66+
### ステップ4: 設定ファイル`ngsw-config.json`を作成します
7267

73-
The Angular CLI needs a service worker configuration file, called `ngsw-config.json`. The configuration file controls how the service worker caches files and data
74-
resources.
68+
Angular CLIには、`ngsw-config.json`というService Workerの設定ファイルが必要です。設定ファイルは、Service Workerがファイルおよびデータリソースをどのようにキャッシュするかを制御します。
7569

76-
You can begin with the boilerplate version from the CLI, which configures sensible defaults for most applications.
70+
CLIからボイラープレート版を始めることができます。このボイラープレート版では、多くのアプリケーションで適切であろう推奨設定が行われています。
7771

78-
Alternately, save the following as `src/ngsw-config.json`:
72+
代わりに、以下を`src/ngsw-config.json`として保存してください。
7973

8074
<code-example path="service-worker-getting-started/src/ngsw-config.json" linenums="false" title="src/ngsw-config.json"> </code-example>
8175

82-
### Step 5: Build the project
76+
### ステップ5: プロジェクトをビルドします
8377

84-
Finally, build the project:
78+
最後にプロジェクトをビルドします。
8579

8680
```sh
8781
ng build --prod
8882
```
8983

90-
The CLI project is now set up to use the Angular service worker.
84+
CLIプロジェクトはAngularにおけるService Workerを使用するように設定されました。
9185

9286

93-
## Service worker in action: a tour
87+
## Service Workerを動かす: ツアー
9488

95-
This section demonstrates a service worker in action,
96-
using an example application.
89+
このセクションでは、サンプルアプリケーションを使用して、Service Workerが実際に動かします。
9790

98-
### Serving with `http-server`
91+
### `http-server`を供給する
9992

100-
Because `ng serve` does not work with service workers, you must use a seperate HTTP server to test your project locally. You can use any HTTP server. The example below uses the [http-server](https://www.npmjs.com/package/http-server) package from npm. To reduce the possibility of conflicts, test on a dedicated port.
93+
`ng serve`はService Workerでは機能しないので、プロジェクトをローカルでテストするためには、別個のHTTPサーバーを使用する必要があります。任意のHTTPサーバーを使用できます。次の例では、npmから[http-server](https://www.npmjs.com/package/http-server)パッケージを使用しています。競合する可能性を減らすために、専用ポートでテストしてください。
10194

102-
To serve with `http-server`, change to the directory containing your web files and start the web server:
95+
`http-server`で供給するために、Webファイルが入っているディレクトリ(訳注:`ng build --prod`で作成されたフォルダ。通常なら`dist`)に移動し、Webサーバーを起動してください。
10396

10497
```sh
10598
cd dist
10699
http-server -p 8080
107100
```
108101

109-
### Initial load
102+
### 最初の読み込み
110103

111-
With the server running, you can point your browser at http://localhost:8080/. Your application should load normally.
104+
サーバーが稼動している状態なら、ブラウザーでhttp://localhost:8080/を指定できます。アプリケーションは正常に読み込まれるでしょう。
112105

113-
**Tip:** When testing Angular service workers, it's a good idea to use an incognito or private window in your browser to ensure the service worker doesn't end up reading from a previous leftover state, which can cause unexpected behavior.
106+
**Tip:** Angular Service Workerをテストするときは、ブラウザでシークレットウィンドウまたはプライベートウィンドウを使うことをお勧めします。以前の状態が残存していると、Service Workerが読み取ったときに予期しない動作を引き起こし終了する可能性があるからです。
114107

115-
### Simulating a network issue
108+
### ネットワークの問題をシミュレートする
116109

117-
To simulate a network issue, disable network interaction for your application. In Chrome:
110+
ネットワークの問題をシミュレートするには、アプリケーションのネットワーク操作を無効にします。Chromeの場合は次になります。
118111

119-
1. Select **Tools** > **Developer Tools** (from the Chrome menu located at the top right corner).
120-
2. Go to the **Network tab**.
121-
3. Check the **Offline box**.
112+
1. ツールバーの右にあるメニューから**その他のツール** > **デベロッパー ツール**を選びます。
113+
2. **Networkタブ**を選びます。
114+
3. **Offlineボックス**をチェックしてください。
122115

123116
<figure>
124117
<img src="generated/images/guide/service-worker/offline-checkbox.png" alt="The offline checkbox in the Network tab is checked">
125118
</figure>
126119

127-
Now the app has no access to network interaction.
120+
これで、アプリケーションはネットワークにアクセスできなくなりました。
128121

129-
For applications that do not use the Angular service worker, refreshing now would display Chrome's Internet disconnected page that says "There is no Internet connection".
122+
AngularにおけるService Workerを使用しないアプリケーションの場合、リフレッシュすると「インターネット接続がありません」と記載されたChromeのインターネット切断ページが表示されます。
130123

131-
With the addition of an Angular service worker, the application behavior changes. On a refresh, the page loads normally.
124+
AngularにおけるService Workerを追加すると、アプリケーションの動作が変更されます。リフレッシュ時に、ページが正常にロードされます。
132125

133-
If you look at the Network tab, you can verify that the service worker is active.
126+
networkタブを見ると、Service Workerがアクティブであることを確認できます。
134127

135128
<figure>
136129
<img src="generated/images/guide/service-worker/sw-active.png" alt="Requests are marked as from ServiceWorker">
137130
</figure>
138131

139-
Notice that under the "Size" column, the requests state is `(from ServiceWorker)`. This means that the resources are not being loaded from the network. Instead, they are being loaded from the service worker's cache.
132+
「サイズ」列の下にある要求状態は、(from ServiceWorker)となっていることに注目してください。これは、リソースがネットワークからロードされていないことを意味します。代わりに、Service Workerのキャッシュからロードされています。
140133

141134

142-
### What's being cached?
135+
### 何がキャッシュされているのか?
143136

144-
Notice that all of the files the browser needs to render this application are cached. The `ngsw-config.json` boilerplate configuration is set up to cache the specific resources used by the CLI:
137+
ブラウザがこのアプリケーションをレンダリングするために必要なすべてのファイルがキャッシュされていることに注意してください。`ngsw-config.json`のボイラープレート設定は、CLIが使用する特定のリソースをキャッシュするように設定されています。
145138

146-
* `index.html`.
147-
* `favicon.ico`.
148-
* Build artifacts (JS and CSS bundles).
149-
* Anything under `assets`.
139+
* `index.html`
140+
* `favicon.ico`
141+
* ビルド成果物(JSおよびCSSバンドル)
142+
* `assets`の下にあるもの(訳注:assets下にさらに階層を作っている場合は、`ngsw-config.json`の設定を階層に合わせて`/assets/**/**`などのように変えてください。)
150143

151-
### Making changes to your application
144+
### アプリケーションを変更する
152145

153-
Now that you've seen how service workers cache your application, the
154-
next step is understanding how updates work.
146+
Service Workerがアプリケーションをキャッシュする方法を見てきました。
147+
次のステップは、アップデートの仕組みを理解することです。
155148

156-
1. If you're testing in an incognito window, open a second blank tab. This will keep the incognito and the cache state alive during your test.
149+
1. シークレットウィンドウでテストする場合は、2つ目のタブを空白で開きます。これにより、テスト中にシークレットとキャッシュの状態が維持されます。
157150

158-
2. Close the application tab, but not the window. This should also close the Developer Tools.
151+
2. アプリケーションタブを閉じますが、ウィンドウは閉じません。これにより、開発者ツールも閉じる必要があります。
159152

160-
3. Shut down `http-server`.
153+
3. `http-server`を落とします。
161154

162-
4. Next, make a change to the application, and watch the service worker install the update.
155+
4. 次に、アプリケーションを変更して、Service Workerが更新プログラムをインストールするのを確認します。
163156

164-
5. Open `src/app/app.component.html` for editing.
157+
5. 編集するために`src/app/app.component.html`を開きます。
165158

166-
6. Change the text `Welcome to {{title}}!` to `Bienvenue à {{title}}!`.
159+
6. `Welcome to {{title}}!`のテキストを`Bienvenue à {{title}}!`に変えます。
167160

168-
7. Build and run the server again:
161+
7. もう一度ビルドしてサーバーを起動します。
169162

170163
```sh
171164
ng build --prod
172165
cd dist
173166
http-server -p 8080
174167
```
175168

176-
### Updating your application in the browser
169+
### ブラウザでアプリケーションを更新する
177170

178-
Now look at how the browser and service worker handle the updated application.
171+
ブラウザとService Workerが、更新されたアプリケーションをどのように処理するかを見てみましょう。
179172

180-
1. Open http://localhost:8080 again in the same window. What happens?
173+
1. 同じウィンドウでもう一度http://localhost:8080を開きます。何が起こりましたか?
181174

182175
<figure>
183176
<img src="generated/images/guide/service-worker/welcome-msg-en.png" alt="It still says Welcome to Service Workers!">
184177
</figure>
185178

186-
What went wrong? Nothing, actually. The Angular service worker is doing its job and serving the version of the application that it has **installed**, even though there is an update available. In the interest of speed, the service worker doesn't wait to check for updates before it serves the application that it has cached.
179+
何が駄目だったのでしょうか?実際には何も悪いことは起こっていません。AngularにおけるService Workerは、利用可能なアップデートがあるにもかかわらず、**インストールされている**アプリケーションのバージョンを提供しています。速度の観点から、Service Workerは、キャッシュされたアプリケーションを提供する前に、更新の確認を待つことはありません。
187180

188-
If you look at the `http-server` logs, you can see the service worker requesting `/ngsw.json`. This is how the service worker checks for updates.
181+
`http-server`ログを見ると、`/ngsw.json`を要求しているService Workerを見ることができます。これは、Service Workerが更新をチェックする方法です。
189182

190-
2. Refresh the page.
183+
2. ページを再読み込みします。
191184

192185
<figure>
193186
<img src="generated/images/guide/service-worker/welcome-msg-fr.png" alt="The text has changed to say Bienvenue à app!">
194187
</figure>
195188

196-
The service worker installed the updated version of your app *in the background*, and the next time the page is loaded or reloaded, the service worker switches to the latest version.
189+
Service Workerは、あなたのアプリケーションの更新版を*バックグラウンドで*インストールし、次にページを読み込んだりリロードしたりすると、Service Workerは最新のバージョンに切り替わります。
197190

198191
<hr />
199192

200-
## More on Angular service workers
193+
## もっとAngularにおけるService Workerを知りたい
201194

202-
You may also be interested in the following:
203-
* [Communicating with service workers](guide/service-worker-communications).
195+
次の記事がお勧めです。
196+
* [Service Workerと通信する](guide/service-worker-communications)

0 commit comments

Comments
 (0)