question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Angular universal not working with service workers

See original GitHub issue

🐞 bug report

Description

Angular Universal (SSR) not working with the service workers, I didn’t get any error but the index.html page not renders in the server as before :

  1. before adding the service workers : https://drive.google.com/open?id=1V7PFlBLD995_HlxLYBrO9IuZ-K0qW33Q

  2. after adding the service workers: https://drive.google.com/open?id=160-k6yVyMNwTkvDeDu4-BlmZkN6k9jf6

🔬 Minimal Reproduction

GitHub repository: https://github.com/walid-hajhussien/Recipe-books Branch: master

🌍 Your Environment

"@angular/animations": "~9.0.3", "@angular/common": "~9.0.3", "@angular/compiler": "~9.0.3", "@angular/core": "~9.0.3", "@angular/forms": "~9.0.3", "@angular/platform-browser": "~9.0.3", "@angular/platform-browser-dynamic": "~9.0.3", "@angular/platform-server": "~9.0.3", "@angular/router": "~9.0.3", "@angular/service-worker": "~9.0.3", "@ngrx/effects": "^9.1.0", "@ngrx/store": "^9.1.0", "@ngrx/store-devtools": "^9.1.0", "@nguniversal/express-engine": "^9.0.1", "angular-user-idle": "^2.2.2", "bootstrap": "^3.4.1", "express": "^4.15.2", "ng-connection-service": "^1.0.4", "rxjs": "~6.5.4", "tslib": "^1.10.0", "zone.js": "~0.10.2"

Anything else relevant? the issue happens when you tried to combine both Angular Universal (SSR) & service workers

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
gkalpakcommented, May 18, 2020

@walid-hajhussien, can you please provide instructions on how to reproduce the issues you are seeing.

If I had to guess, I would say that what happens is this:

  • Before the SW has been installed/activated, the index.html file is served from the server, where it is rendered before being sent to the client.
  • Once the SW has been installed and activated, index.html is served from the SW (so no SSR, since the request never hits the server).

This is generally working as intended. Generally, the idea of prerendering is that it kicks in on the first load (to speed up the first rendering) and on subsequent loads the SW takes over and speeds up the rendering by serving the HTML and other resources from the local cache (and only fetching the necessary data). Prerendering is also useful in other contexts (such as SEO, link previews, etc.) where the clients are not using ServiceWorkers.

0reactions
angular-automatic-lock-bot[bot]commented, Jun 26, 2020

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular Universal 13 Not Working with Service Worker on ...
npm i -g @angular/cli - installs latest version 13; ng new test - then open project; ng add @nguniversal/express-engine; ng add @angular/pwa.
Read more >
Error in Service Worker when using Angular Universal #2175
I use it in my system made in Angular, Angular Universal together with Service Worker. However after doing build(npm run build:ssr) running ......
Read more >
How to Enable Server-Side Rendering and PWA for Your ...
Angular uses a built-in tool (Angular Universal) to help you enable SSR. ... I'm not going to explain how service workers work.
Read more >
Angular Service Worker - Step-By-Step Guide
The Angular Service Worker can cache all sorts of content in the browser Cache Storage. This is a Javascript-based key/value caching mechanism ...
Read more >
Service worker in production - Angular
The Angular service worker continues to serve a resource even after its HTTP caching headers indicate that it is no longer valid. At...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found