From b74df20c2a035bd0fefdf29fa7fd5ea1a8764eca Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Tue, 4 Jun 2019 16:19:53 +0300 Subject: [PATCH] docs(service-worker): mention that HTTPS is required, unless on `localhost` (#30847) Fixes #30823 PR Close #30847 --- .../guide/service-worker-getting-started.md | 9 ++++++++- aio/content/guide/service-worker-intro.md | 18 +++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/aio/content/guide/service-worker-getting-started.md b/aio/content/guide/service-worker-getting-started.md index 5d36fdf3cf..241bd5caea 100644 --- a/aio/content/guide/service-worker-getting-started.md +++ b/aio/content/guide/service-worker-getting-started.md @@ -59,6 +59,13 @@ With the server running, you can point your browser at http://localhost:8080/. Y **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. +
+ +**Note:** +If you are not using HTTPS, the service worker will only be registered when accessing the app on `localhost`. + +
+ ### Simulating a network issue To simulate a network issue, disable network interaction for your application. In Chrome: @@ -156,4 +163,4 @@ The service worker installed the updated version of your app *in the background* ## More on Angular service workers You may also be interested in the following: -* [Communicating with service workers](guide/service-worker-communications). \ No newline at end of file +* [Communicating with service workers](guide/service-worker-communications). diff --git a/aio/content/guide/service-worker-intro.md b/aio/content/guide/service-worker-intro.md index 2eba216fb6..e9678ca1ff 100644 --- a/aio/content/guide/service-worker-intro.md +++ b/aio/content/guide/service-worker-intro.md @@ -6,16 +6,16 @@ At its simplest, a service worker is a script that runs in the web browser and m Service workers function as a network proxy. They intercept all outgoing HTTP requests made by the application and can choose how to respond to them. For example, they can query a local cache and deliver a cached response if one is available. Proxying isn't limited to requests made through programmatic APIs, such as `fetch`; it also includes resources referenced in HTML and even the initial request to `index.html`. Service worker-based caching is thus completely programmable and doesn't rely on server-specified caching headers. -Unlike the other scripts that make up an application, such as the Angular app bundle, the service worker is preserved after the user closes the tab. The next time that browser loads the application, the service worker loads first, and can intercept every request for resources to load the application. If the service worker is designed to do so, it can *completely satisfy the loading of the application, without the need for the network*. +Unlike the other scripts that make up an application, such as the Angular app bundle, the service worker is preserved after the user closes the tab. The next time that browser loads the application, the service worker loads first, and can intercept every request for resources to load the application. If the service worker is designed to do so, it can *completely satisfy the loading of the application, without the need for the network*. -Even across a fast reliable network, round-trip delays can introduce significant latency when loading the application. Using a service worker to reduce dependency on the network can significantly improve the user experience. +Even across a fast reliable network, round-trip delays can introduce significant latency when loading the application. Using a service worker to reduce dependency on the network can significantly improve the user experience. ## Service workers in Angular Angular applications, as single-page applications, are in a prime position to benefit from the advantages of service workers. Starting with version 5.0.0, Angular ships with a service worker implementation. Angular developers can take advantage of this service worker and benefit from the increased reliability and performance it provides, without needing to code against low-level APIs. -Angular's service worker is designed to optimize the end user experience of using an application over a slow or unreliable network connection, while also minimizing the risks of serving outdated content. +Angular's service worker is designed to optimize the end user experience of using an application over a slow or unreliable network connection, while also minimizing the risks of serving outdated content. The Angular service worker's behavior follows that design goal: @@ -33,14 +33,18 @@ Installing the Angular service worker is as simple as including an `NgModule`. I Your application must run in a web browser that supports service workers. Currently, service workers are supported in the latest versions of Chrome, Firefox, Edge, Safari, Opera, UC Browser (Android version) and Samsung Internet. Browsers like IE and Opera Mini do not provide the support. To learn more about other browsers that are service worker ready, see the [Can I Use](https://caniuse.com/#feat=serviceworkers) page and [MDN docs](https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API). +In addition, in order for service workers to be registered, the app must be accessed over HTTPS, not HTTP. Browsers will ignore service workers on pages that are served over an insecure connection. The reason is that service workers are quite powerful, so extra care needs to be taken to ensure the service worker script has not been tampered with. + +There is one exception to this rule: To make local development easier, browsers do _not_ require a secure connection when accessing an app on `localhost`. + ## Related resources -For more information about service workers in general, see [Service Workers: an Introduction](https://developers.google.com/web/fundamentals/primers/service-workers/). +For more information about service workers in general, see [Service Workers: an Introduction](https://developers.google.com/web/fundamentals/primers/service-workers/). -For more information about browser support, see the [browser support](https://developers.google.com/web/fundamentals/primers/service-workers/#browser_support) section of [Service Workers: an Introduction](https://developers.google.com/web/fundamentals/primers/service-workers/), Jake Archibald's [Is Serviceworker ready?](https://jakearchibald.github.io/isserviceworkerready/), and -[Can I Use](http://caniuse.com/#feat=serviceworkers). +For more information about browser support, see the [browser support](https://developers.google.com/web/fundamentals/primers/service-workers/#browser_support) section of [Service Workers: an Introduction](https://developers.google.com/web/fundamentals/primers/service-workers/), Jake Archibald's [Is Serviceworker ready?](https://jakearchibald.github.io/isserviceworkerready/), and +[Can I Use](http://caniuse.com/#feat=serviceworkers). -The remainder of this Angular documentation specifically addresses the Angular implementation of service workers. +The remainder of this Angular documentation specifically addresses the Angular implementation of service workers. ## More on Angular service workers