-
Notifications
You must be signed in to change notification settings - Fork 483
SSR angular using Service Workers #1740
Comments
Hi @joejordanbrown, Thanks for going in such detail 👍 Side note: this is partially related to: angular/angular-cli#2305 |
Hi @alan-agius4, I thought I'd try and accomplish this using I'm still working through the Universal code base to make sure I understand how it all works. I have started to make the custom engine to test out the possibility and to see if anything else comes to light that I may have overlooked. The Angular CLI build now has Regarding the angular/angular-cli#2305 post, I have already read every comment and couldn't find much traction on that, the feature request is from 2016. I've also scanned every single mention of My assumption when I read the comment from @filipesilva angular/angular-cli#2305 (comment) was that https://angular.io/guide/web-worker was as far as Angular was willing to integrate Web Workers right now but I may be wrong. I'll update this issue with any issues I come across. |
Would love to see Angular moving forward on this. I'm currently having to use a Vue based solution to do SSR on Cloudflare |
+1 |
Let continue tracking this in angular/angular-cli#25718 |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
🚀 Feature request
Description
Support for rendering Angular using Service Workers, then we can SSR Angular apps using Cloudflare Workers serverless functions.
I don't believe this is currently possible with Angular if it is I've not found any documentation in deploying and rendering the whole app in a service worker. I know it's easy to render with React to Service Workers using
react-dom/server
you can see an example on Cloudflare blog https://blog.cloudflare.com/serverless-pwa-react-cloudflare-workers/ and the source on GitHub https://github.com/cloudflare/workers-react-pwa-example.Cloudflare Workers are not compatible with Node.js API, so we can't use Universal express or hapi rendering engines.
The Angular renderer that works in the browser should be compatible in some degree as long as it doesn't use window or document. I'm not sure if the Universal core rendering engine requires Node.js API's to function or if it's possible to run the runtime in a browser.
HTTP
Workers only supports fetch for HTTP requests, where Angular HttpClient I believe uses
XMLHttpRequest
andjsonp
only.Fetch would need to be integrated into HttpClient or requests intercepted to use fetch.
Build
The build would need a slight change from the one used when building the server.ts currently. It requires
target: 'webworker'
in the webpack config.See Cloudflare Workers Wrangler webpack docs for examples.
Storage
Serverless doesn't have a filesystem to access. Cloudflare workers use a KV store,
Again because it doesn't support the Node.js API you don't have
fs
etc. The KV store is where you would store thedist/app-name/browser
assets of the Angular app, you would import the@cloudflare/kv-asset-handler
package which has methods to retrieve assets, for example, server.ts requireddist/app-name/browser/index.html
for use in the Universal engine.I believe I have covered most of the differences when comparing Node.js vs Workers platform.
This universal render should focus on working with service/web workers and not specifically Cloudflare workers. There are other SaaS and open source serverless platforms that are looking to provide a service worker type serverless functions service because of the benefits it has over Node.js runtime. It also might be included in newer JavaScript runtime in the near future that would benefit from this for SSR.
If there's anything that I've overlooked, then please comment.
The text was updated successfully, but these errors were encountered: