swagger icon indicating copy to clipboard operation
swagger copied to clipboard

Optimize swagger-ui-dist loading performance

Open edgesite opened this issue 3 years ago • 2 comments

PR Checklist

Please check if your PR fulfills the following requirements:

  • [x] The commit message follows our guidelines: https://github.com/nestjs/nest/blob/master/CONTRIBUTING.md
  • [x] Tests for the changes have been added (for bug fixes / features)
  • [x] Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • [ ] Bugfix
  • [ ] Feature
  • [ ] Code style update (formatting, local variables)
  • [x] Refactoring (no functional changes, no api changes)
  • [ ] Build related changes
  • [ ] CI related changes
  • [ ] Other... Please describe:

Does this PR introduce a breaking change?

  • [ ] Yes
  • [x] No

Other information

code:

const start = Date.now();
const config = new DocumentBuilder().build();
const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('api', app, document);
console.log(`Swagger loaded in ${Date.now() - start}ms`);

before: Swagger loaded in 101ms after: Swagger loaded in 26ms see: https://github.com/swagger-api/swagger-ui/issues/4502

edgesite avatar Sep 11 '22 07:09 edgesite

AFAIR swagger-ui-dist suggests to use the getAbsoluteFSPath function for this

kamilmysliwiec avatar Sep 12 '22 06:09 kamilmysliwiec

getAbsoluteFSPath function is actually a shorthand of require('absolute-path.js'), and the absolute-path.js have test, so we can concern it as stable API.

edgesite avatar Sep 12 '22 06:09 edgesite

lgtm

kamilmysliwiec avatar Oct 26 '22 08:10 kamilmysliwiec