|
1 |
| -# Getting started with service workers |
| 1 | +# Comenzando con los Trabajadores de Servicio |
2 | 2 |
|
3 | 3 |
|
4 |
| -This document explains how to enable Angular service worker support in projects that you created with the [Angular CLI](cli). It then uses a simple example to show you a service worker in action, demonstrating loading and basic caching. |
| 4 | +Este documento explica como habilitar el soporte de Trabajadores de Servicio Angular en proyectos que creaste con [Angular CLI](cli). Luego usa un ejemplo simple para mostrarle un trabajador de servicio en acción demostrando la carga y almacenamiento en caché básico. |
5 | 5 |
|
6 |
| -#### Prerequisites |
| 6 | +#### Prerequisitos |
7 | 7 |
|
8 |
| -A basic understanding of the information in [Introduction to Angular service workers](guide/service-worker-intro). |
| 8 | +Una comprensión básica de la información en [Introduction to Angular service workers](guide/service-worker-intro). |
9 | 9 |
|
10 | 10 |
|
11 |
| -## Adding a service worker to your project |
| 11 | +## Agregando un trabajador de servicio a tu proyecto |
12 | 12 |
|
13 |
| -To set up the Angular service worker in your project, use the CLI command `ng add @angular/pwa`. It takes care of configuring your app to use service workers by adding the `service-worker` package along |
14 |
| -with setting up the necessary support files. |
| 13 | +Para configurar un trabajador de servicio Angular en su proyecto, use el comando CLI `ng add @angular/pwa`. Se encarga de configurar su aplicación para usar trabajador de servicio agregando el paquete `service-worker` junto con la preparación de los archivos de soporte necesarios. |
15 | 14 |
|
16 | 15 | ```sh
|
17 | 16 | ng add @angular/pwa --project *project-name*
|
18 | 17 | ```
|
19 | 18 |
|
20 |
| -The above command completes the following actions: |
| 19 | +El anterior comando completa las siguientes accciones: |
21 | 20 |
|
22 |
| -1. Adds the `@angular/service-worker` package to your project. |
23 |
| -2. Enables service worker build support in the CLI. |
24 |
| -3. Imports and registers the service worker in the app module. |
25 |
| -4. Updates the `index.html` file: |
26 |
| - * Includes a link to add the `manifest.webmanifest` file. |
27 |
| - * Adds meta tags for `theme-color`. |
28 |
| -5. Installs icon files to support the installed Progressive Web App (PWA). |
29 |
| -6. Creates the service worker configuration file called [`ngsw-config.json`](/guide/service-worker-config), which specifies the caching behaviors and other settings. |
| 21 | +1. Agrega el paquete `@angular/service-worker` en su proyecto. |
| 22 | +2. Habilita el soporte de trabajador de servicio en la interfaz de línea de comandos. |
| 23 | +3. importa y registra el trabajador de servicio en el módulo de la aplicación. |
| 24 | +4. Actualiza el archivo `index.html`: |
| 25 | + * Incluye un enlace para agregar el archivo `manifest.webmanifest`. |
| 26 | + * Agrega metaetiquetas para `theme-color`. |
| 27 | +5. Instala archivos de iconos para soportar la aplición web progresiva (PWA) instalada. |
| 28 | +6. Crea el archivo de configuración de trabajador de servicio llamado [`ngsw-config.json`](/guide/service-worker-config), el cual especifica los comportamientos de almacenamiento en caché y otras configuraciones. |
30 | 29 |
|
31 | 30 |
|
32 |
| - Now, build the project: |
| 31 | +Ahora, crear el proyecto: |
33 | 32 |
|
34 | 33 | ```sh
|
35 | 34 | ng build --prod
|
36 | 35 | ```
|
37 | 36 |
|
38 |
| -The CLI project is now set up to use the Angular service worker. |
| 37 | +El proyecto CLI está ahora preparado para usar trabajador de servicio de Angular. |
39 | 38 |
|
| 39 | +## Trabajador de servicio en acción: un recorrido |
40 | 40 |
|
41 |
| -## Service worker in action: a tour |
| 41 | +Esta sección demuestra un trabajador de servicio en acción, usando una aplicación ejemplo. |
42 | 42 |
|
43 |
| -This section demonstrates a service worker in action, |
44 |
| -using an example application. |
| 43 | +### Sirviendo con `http-server` |
45 | 44 |
|
46 |
| -### Serving with `http-server` |
| 45 | +Debido a que `ng serve` no funciona con trabajador de servicios, debe usar un servidor HTTP separado para probar su proyecto localmente. Puede usar cualquier servidor HTTP. El siguiente ejemplo usa el paquete[http-server](https://www.npmjs.com/package/http-server) de npm. Para reducir la posibilidad de conflictos y evitar servir contenido obsoleto, pruebe en un puerto dedicado y deshabilite el almacenamiento en caché. |
47 | 46 |
|
48 |
| -Because `ng serve` does not work with service workers, you must use a separate 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 and avoid serving stale content, test on a dedicated port and disable caching. |
49 |
| - |
50 |
| -To serve the directory containing your web files with `http-server`, run the following command: |
| 47 | +Para servir el directorio que contiene sus archivos web con `http-server`, ejecute el siguiente comando: |
51 | 48 |
|
52 | 49 | ```sh
|
53 | 50 | http-server -p 8080 -c-1 dist/<project-name>
|
54 | 51 | ```
|
55 | 52 |
|
56 |
| -### Initial load |
| 53 | +### Carga inicial |
57 | 54 |
|
58 |
| -With the server running, you can point your browser at http://localhost:8080/. Your application should load normally. |
| 55 | +Con el servidor en ejecución, puede apuntar su navegador a http://localhost:8080/. Su aplicación debería cargarse normalmente. |
59 | 56 |
|
60 |
| -**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. |
| 57 | +**Consejo** Cuando pruebe trabajador de servicios de Angular, es una buena idea usar una ventana privada o de incognito en su navegador para asegurarse de que el trabajador de servicio no termine leyendo de un estado sobrante anterior, el cual puede causar un comportamiento inesperado. |
61 | 58 |
|
62 | 59 | <div class="alert is-helpful">
|
63 | 60 |
|
64 |
| -**Note:** |
65 |
| -If you are not using HTTPS, the service worker will only be registered when accessing the app on `localhost`. |
| 61 | +**Nota:* |
| 62 | +Si no está utilizando HTTPS, el trabajador de servicio solo se registrará cuando acceda a la aplicación en `localhost`. |
66 | 63 |
|
67 | 64 | </div>
|
68 | 65 |
|
69 |
| -### Simulating a network issue |
| 66 | +### Simulando un problema de red |
70 | 67 |
|
71 |
| -To simulate a network issue, disable network interaction for your application. In Chrome: |
| 68 | +Para simular un problema de red, deshabilite la interacción de red para su aplicación: En Chrome: |
72 | 69 |
|
73 |
| -1. Select **Tools** > **Developer Tools** (from the Chrome menu located at the top right corner). |
74 |
| -2. Go to the **Network tab**. |
75 |
| -3. Check the **Offline box**. |
| 70 | +1. Seleccione **Herramientas** > **Herramientas de desarrollador** (desde el menu de Chrome ubicado en la esquina superior derecha). |
| 71 | +2. Vaya a **pestaña red**. |
| 72 | +3. Compruebe que **caja esté desactivada** |
76 | 73 |
|
77 | 74 | <div class="lightbox">
|
78 |
| - <img src="generated/images/guide/service-worker/offline-checkbox.png" alt="The offline checkbox in the Network tab is checked"> |
| 75 | + <img src="generated/images/guide/service-worker/offline-checkbox.png" alt="The offline checkbox in the Network tab is checked"> |
79 | 76 | </div>
|
80 | 77 |
|
81 |
| -Now the app has no access to network interaction. |
| 78 | +Ahora la aplicación no tiene acceso a la interacción de red. |
82 | 79 |
|
83 |
| -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". |
| 80 | +Para aplicaciones que no usen trabajador de servicio de Angular, la actualización ahora mostraría la página de desconectado de Chrome que dice "No hay conexión a internet". |
84 | 81 |
|
85 |
| -With the addition of an Angular service worker, the application behavior changes. On a refresh, the page loads normally. |
| 82 | +Con la incorporación de un trabajador de servicio Angular, el comportamiento de la aplicación cambia. En una actualización, la página carga normarmente. |
86 | 83 |
|
87 |
| -If you look at the Network tab, you can verify that the service worker is active. |
| 84 | +Si observa la pestaña de red, puede verificar que trabajador de servicio esté activo. |
88 | 85 |
|
89 | 86 | <div class="lightbox">
|
90 | 87 | <img src="generated/images/guide/service-worker/sw-active.png" alt="Requests are marked as from ServiceWorker">
|
91 | 88 | </div>
|
92 | 89 |
|
93 |
| -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. |
| 90 | +Note que debajo de la columna "Tamaño", el estado de las solicitudes es `(from ServiceWorker)`. Esto significa que los recursos no estan siendo cargados desde la red. En su lugar estan siendo cargados desde la memoria caché del service worker. |
94 | 91 |
|
95 | 92 |
|
96 |
| -### What's being cached? |
| 93 | +### Qué esta siendo almacenado en caché? |
97 | 94 |
|
98 |
| -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: |
| 95 | +Note que todos los archivos que el navegador necesita para procesar esta aplicación son almacenados en caché. La configuración estándar `ngsw-config.json` está preparada para almacenar los recursos específicos usados por el CLI: |
99 | 96 |
|
100 | 97 | * `index.html`.
|
101 | 98 | * `favicon.ico`.
|
102 |
| -* Build artifacts (JS and CSS bundles). |
103 |
| -* Anything under `assets`. |
104 |
| -* Images and fonts directly under the configured `outputPath` (by default `./dist/<project-name>/`) or `resourcesOutputPath`. See [`ng build`](cli/build) for more information about these options. |
| 99 | +* Construir artefactos (paquetes JS y CSS). |
| 100 | +* Cualquier cosa bajo `assets`. |
| 101 | +* Imagenes y fuentes directamente bajo el `outputPath` configurado (por defecto `./dist/<project-name>/`) o `resourcesOutputPath`. Mire [`ng build`](cli/build) para más información acerca de estas opciones. |
105 | 102 |
|
106 | 103 |
|
107 | 104 | <div class="alert is-helpful">
|
108 |
| -Pay attention to two key points: |
| 105 | +Preste atención a dos puntos clave: |
109 | 106 |
|
110 |
| -1. The generated `ngsw-config.json` includes a limited list of cacheable fonts and images extentions. In some cases, you might want to modify the glob pattern to suit your needs. |
| 107 | +1. El `ngsw-config.json` generado incluye una lista limitada de fuentes almacenables en caché y extensiones de imágenes. En algunos casos podrías querer modificar el patrón global para adaptarlo a sus necesidades. |
111 | 108 |
|
112 |
| -1. If `resourcesOutputPath` or `assets` paths are modified after the generation of configuration file, you need to change the paths manually in `ngsw-config.json`. |
| 109 | +2. Si las rutas `resourcesOutputPath` o `assets` son modificadas después de la generación del archivo de configuración, necesita cambiar las rutas manualmente en `ngsw-config.json`. |
113 | 110 | </div>
|
114 | 111 |
|
115 |
| -### Making changes to your application |
| 112 | +### Haciendo cambios en su aplicación |
116 | 113 |
|
117 |
| -Now that you've seen how service workers cache your application, the |
118 |
| -next step is understanding how updates work. |
| 114 | +Ahora que ha visto como trabajadores de servicio alamcenan su aplicación, el próximo paso es entender como funcionan las actualizaciones. |
119 | 115 |
|
120 |
| -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. |
| 116 | +1. Si esta probando en una ventana de incónito, abra una segunda pestaña en blanco. Esto mantendrá vivo el incógnito y el estado de cache durante la prueba. |
121 | 117 |
|
122 |
| -2. Close the application tab, but not the window. This should also close the Developer Tools. |
| 118 | +2. Cierre la pestaña de la aplicación, pero no la ventana. Este también debería cerrar las herramientas de desarrollador. |
123 | 119 |
|
124 |
| -3. Shut down `http-server`. |
| 120 | +3. Apague `http-server`. |
125 | 121 |
|
126 |
| -4. Next, make a change to the application, and watch the service worker install the update. |
| 122 | +4. A continuación, realice un cambio en la aplicación, y observe como el trabajador de servicio instala la actualización. |
127 | 123 |
|
128 |
| -5. Open `src/app/app.component.html` for editing. |
| 124 | +5. Abra `src/app/app.component.html` para editarlo. |
129 | 125 |
|
130 |
| -6. Change the text `Welcome to {{title}}!` to `Bienvenue à {{title}}!`. |
| 126 | +6. Cambie el texto `Welcome to {{title}}!` a `Bienvenue à {{title}}!`. |
131 | 127 |
|
132 |
| -7. Build and run the server again: |
| 128 | +7. Cree y ejecute el servidor nuevamente. |
133 | 129 |
|
134 | 130 | ```sh
|
135 | 131 | ng build --prod
|
136 | 132 | http-server -p 8080 -c-1 dist/<project-name>
|
137 | 133 | ```
|
| 134 | +### Actualizando su aplicación en el navegador |
138 | 135 |
|
139 |
| -### Updating your application in the browser |
140 |
| - |
141 |
| -Now look at how the browser and service worker handle the updated application. |
| 136 | +Ahora observe como el navegador y el trabajador de servicio manejan la aplicación actulizada. |
142 | 137 |
|
143 |
| -1. Open http://localhost:8080 again in the same window. What happens? |
| 138 | +1. Abra http://localhost:8080 nuevamente en la misma ventana. Qué sucede? |
144 | 139 |
|
145 | 140 | <div class="lightbox">
|
146 | 141 | <img src="generated/images/guide/service-worker/welcome-msg-en.png" alt="It still says Welcome to Service Workers!">
|
147 | 142 | </div>
|
148 | 143 |
|
149 |
| -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. |
| 144 | +¿Qué salio mal? Nada en realidad. El trabajador de servicio de Angular está haciendo este trabajo y entregando la versión de la aplicación que tiene **instalada** aunque hay una actualización disponible. En aras de la velocidad, el trabajador de servicio no espera para verificar actualizaciones antes de servir la aplicación que tiene almacenado en caché. |
150 | 145 |
|
151 |
| -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. |
| 146 | +Si observa los registros de `http-server`, puede ver el trabajador de servicio solicitando `/ngsw.json`. Así es como el trabajador de servicio busca actualizaciones. |
152 | 147 |
|
153 |
| -2. Refresh the page. |
| 148 | +2. Recargue la página. |
154 | 149 |
|
155 | 150 | <div class="lightbox">
|
156 | 151 | <img src="generated/images/guide/service-worker/welcome-msg-fr.png" alt="The text has changed to say Bienvenue à app!">
|
157 | 152 | </div>
|
158 | 153 |
|
159 |
| -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. |
| 154 | +El trabajador de servicio instaló la versión actualizada de su aplicación *en segundo plano*, y la próxima vez que la página es carguada o recargada, el trabajador de servicio cambia a la última versión. |
160 | 155 |
|
161 | 156 | <hr />
|
162 | 157 |
|
163 |
| -## More on Angular service workers |
| 158 | +## Más sobre trabajadores de servicio de Angular |
164 | 159 |
|
165 |
| -You may also be interested in the following: |
166 |
| -* [Communicating with service workers](guide/service-worker-communications). |
| 160 | +También le puede interesar lo siguiente: |
| 161 | +* [Comunicarse con los trabajadores de servicio](guide/service-worker-communications). |
0 commit comments