-
Notifications
You must be signed in to change notification settings - Fork 474
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
perf(swagger-module): lazy load swagger-ui-dist module #2023
perf(swagger-module): lazy load swagger-ui-dist module #2023
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will be great for serverless apps! thanks
Could we use |
@kamilmysliwiec we could, but that will require users to add |
So this is something that makes me a little concerned. If we wanted to support ESM (eventually), we'd have to use async import anyway (for lazy imports) |
I'm fine doing that change. However, do I need to update any doc to warn users about the need to await the setup method in the next release? |
wouldn't that be a breaking change? Maybe we could keep |
Yeah that would be a breaking change, and that's why I'm concerned too. If we stick with the current implementation (top-level require), even if we decide to move to ESM one day, we wouldn't have to introduce any breaking changes |
yeah, indeed. Another solution that I can think of: SwaggerModule.setup('api', app, document) // this won't use lazy loading
await SwaggerModule.setup('api', app, document, { lazy: true }) then in the next major release of |
Hey @kamilmysliwiec, what approach should we take? I'm not an ESM expert, but I'm happy to help and get this PR merged 🙂 |
🏓 |
Let's ignore ESM for now. LGTM |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
swagger-ui-dist
module is loaded before its utilization, and it loads two large files (listed below), causing some overhead on the app initialization (~800ms in a medium app).Issue Number: N/A
What is the new behavior?
swagger-ui-dist
module is loaded only when serving the Swagger HTML (SwaggerModule.serveStatic
).Does this PR introduce a breaking change?
Other information
Bubbleprof from Clinicjs using the E2E app.