HTTP/2 support f
I've been testing AWS Lambda + aws-serverless-express + Angular (SSR).
1) Lambda -> aws-serverless-express.
2) Express bootstraps Angular application's
3) During bootstrap process, application fetches resources from CloudFront and other resources
4) Rendered HTML -page is returned to the user.
I've been testing this setup locally and rendering is a lot faster with spdy -library. It reduces startup time by several seconds
I haven't been able to figure out how HTTP/2 support should be added using aws-serverless-express -library. Or is it even possible? If possible how it should be done?
I would appreciate your suggestions and comments on this :)
CloudFront has HTTP/2 support. If you use REGIONAL API Gateway or Lambda@Edge with your own CloudFront, does that help?
CloudFront supports HTTP/2 but it requires that your browser or server support its. Angular uses HTTP/2 if your browser or server supports its.
In SSR (Server Side Rendering) HTTP/2 support comes from underlying HTTP server which is in this case Express.
Please correct me if I have misunderstood something :) I'm not an expert on the subject.
I believe the limitation here is API Gateway. If you use ALB or Lambda@Edge as an eve not source you might be able to get this to work?
Sorry, I do not understand your comment about API Gateway / ALB . Why it's relevant in SSR?
I'll try to explain this in more detail.
Client:
- Client request HTML -page for the first time.
Server:
-
Request starts Angular's bootstrap process.
-
Before application can start rendering process / generating HTML, it may have to fetch external resources using HTTP. For example UI's translation files, data for select menus etc. This means that process may involve a lot of HTTP -requests depending on the application. If HTTP/1 is used these all request are done one by one insted of requesting them simultanously (HTTP/2). Which protocol is used in to make these HTTP - request, is determined by underlying HTTP -server (Express). It doesn't matter where the resources are located, behind API Gateway or same where else if requester (Express) doesn't support HTTP/2 -> requests are always done with HTTP/1.
-
When all needed sources are fetched / HTTP -request, server side application can render/generate actual HTML -page.
-
Generated HTML -page is returned to the client.
Client:
- Client parses HTML -document and constructs a DOM tree.
- Client fetches resources (style sheet, images etc). These calls are usually done via API Gateway. Most browsers support HTTP/2 -> Resource are fetched simultanously. Problem is not here.