serverless-express icon indicating copy to clipboard operation
serverless-express copied to clipboard

HTTP/2 support f

Open GipHub123 opened this issue 5 years ago • 5 comments

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 :)

GipHub123 avatar Dec 28 '20 17:12 GipHub123

CloudFront has HTTP/2 support. If you use REGIONAL API Gateway or Lambda@Edge with your own CloudFront, does that help?

brettstack avatar Jan 11 '21 23:01 brettstack

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.

GipHub123 avatar Jan 12 '21 15:01 GipHub123

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?

brettstack avatar Jan 29 '21 10:01 brettstack

Sorry, I do not understand your comment about API Gateway / ALB . Why it's relevant in SSR?

GipHub123 avatar Jan 29 '21 14:01 GipHub123

I'll try to explain this in more detail.


Client:

  1. Client request HTML -page for the first time.

Server:

  1. Request starts Angular's bootstrap process.

  2. 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.

  3. When all needed sources are fetched / HTTP -request, server side application can render/generate actual HTML -page.

  4. Generated HTML -page is returned to the client.


Client:

  1. Client parses HTML -document and constructs a DOM tree.
  2. 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.

GipHub123 avatar Jan 29 '21 14:01 GipHub123