angular-service-worker

Angular ServiceWorkers + MIME type error

馋奶兔 提交于 2019-12-05 15:57:40
问题 I'm trying to add service workers to our existing angular (5.2, CLI 1.7.1) application. I did everything I was suppose to: I created ngsw-config.json I run the the ng set apps.0.serviceWorker=true command so I have "serviceWorker": true, in angular-cli.json . I have installed "@angular/service-worker": "5.2.9" I added to app.module.ts : import { ServiceWorkerModule } from '@angular/service-worker'; imports: [ ... ServiceWorkerModule.register('/ngsw-worker.js', { enabled: environment

Angular - is it ok to register ngsw-worker.js twice (in main.ts & app.module.ts)?

允我心安 提交于 2019-12-05 09:31:34
I am registering ngsw-worker.js in both main.ts and app.module.ts. Is this ok? Such as would it create 2 instances of service worker? Would there be a conflict in service worker? main.ts platformBrowserDynamic().bootstrapModule(AppModule).then(() => { if ('serviceWorker' in navigator && environment.production) { navigator.serviceWorker.register('/ngsw-worker.js'); } }).catch(err => console.log(err)); app.module.ts @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, ServiceWorkerModule.register('/ngsw-worker.js', {enabled: environment.production}), AppRoutingModule ],

Angular 5 Service Worker not working

拈花ヽ惹草 提交于 2019-12-05 00:20:09
I try to add service worker to my project after updating to angular 5 and have some problems. I add imports to app.module.ts: import {ServiceWorkerModule} from '@angular/service-worker'; import {environment} from '../environments/environment'; ... environment.production ? ServiceWorkerModule.register('/ngsw-worker.js') : [], execute $ ng set apps.0.serviceWorker=true to allow service workers in project generate config: { "index": "/index.html", "assetGroups": [ { "name": "app", "installMode": "prefetch", "resources": { "files": [ "/index.html" ], "versionedFiles": [ "/*.bundle.css", "/*.bundle

Check Service worker installation progress from component (angular)

我与影子孤独终老i 提交于 2019-12-04 18:33:45
I have updated my angular app into PWA, since I need to preload all of the assets on the first launch (application have a lots of images, which are used for UI). That's why I would like to show some kind of spinner/loading bar during service worker install event and hide it when it's done. So first question - is it possible to handle this event from the component? I have found this example and tried to add it inside first component, that loads on app launch, but didn't get any logs. So probably it doesn't work that way. ngOnInit() { self.addEventListener('install', event => { this.log(

How to make Angular Universal and PWA work together?

若如初见. 提交于 2019-12-04 14:38:45
问题 I have a SSR Angular app which I am trying to transform into a PWA. I want it to be server-side rendered for SEO and for the "fast first rendering" that it provides. The PWA mode works fine when combined with SSR, but once the app is loaded, when we refresh it, the client index HTML file is loaded instead of the server-side rendered page. I have dug into the code of ngsw-worker.js and I saw this: // Next, check if this is a navigation request for a route. Detect circular // navigations by

Angular Service Worker on the browsers that do not support it

ⅰ亾dé卋堺 提交于 2019-12-04 10:56:29
Angular team made a great job and introduced service workers support in the version 5. The documentation is quite helpful and I can really see how the things will work right after reading the related articles, however there is one topic that is not covered there. How does this all work in the browsers that do not support service workers. This is what's being said: Your application must run in a web browser that supports service workers. Currently, the latest versions of Chrome and Firefox are supported. To learn about other browsers that are service worker ready, see the Can I Use page. Can I

Angular ServiceWorkers + MIME type error

半腔热情 提交于 2019-12-04 01:39:22
I'm trying to add service workers to our existing angular (5.2, CLI 1.7.1) application. I did everything I was suppose to: I created ngsw-config.json I run the the ng set apps.0.serviceWorker=true command so I have "serviceWorker": true, in angular-cli.json . I have installed "@angular/service-worker": "5.2.9" I added to app.module.ts : import { ServiceWorkerModule } from '@angular/service-worker'; imports: [ ... ServiceWorkerModule.register('/ngsw-worker.js', { enabled: environment.production }), ] I even tried to add this piece of code (which I found as a solution somewhere) to main.ts

How to make Angular Universal and PWA work together?

ⅰ亾dé卋堺 提交于 2019-12-03 10:09:15
I have a SSR Angular app which I am trying to transform into a PWA. I want it to be server-side rendered for SEO and for the "fast first rendering" that it provides. The PWA mode works fine when combined with SSR, but once the app is loaded, when we refresh it, the client index HTML file is loaded instead of the server-side rendered page. I have dug into the code of ngsw-worker.js and I saw this: // Next, check if this is a navigation request for a route. Detect circular // navigations by checking if the request URL is the same as the index URL. if (req.url !== this.manifest.index && this

Angular Service Worker - Failed to load resource: the server responded with a status of 504 (Gateway Timeout)

五迷三道 提交于 2019-12-02 21:03:28
I am using the Angular-CLI 1.6.6 and @angular/service-worker 5.2.5 in our Angular 5.2.5 app. Everything works fine on the local lite-server, as well as on the production server, except for one error message popping in our production environment: Failed to load resource: the server responded with a status of 504 (Gateway Timeout) Looking into the ngsw-worker.js script I found the lines (2466 following) where the error message above is generated: async safeFetch(req) { try { return await this.scope.fetch(req); } catch (err) { this.debugger.log(err, `Driver.fetch(${req.url})`); return this

Angular 6 PWA with Node not working

♀尐吖头ヾ 提交于 2019-12-02 11:15:57
问题 I have a Angular 6 app that works and registers the SW when served with http-server --port 8080 command as you can see here: But when I serve the files from my Node / Express application that they are meant to be served. The service worker won't register, tried running the app from localhost and also from Heroku but it's the same. Application works otherwise. Any idea what can cause this? 回答1: I think this issue is to do with the path that @angular/cli uses when registering the service worker