Skip to content
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: Reduce package size by removing sourceMaps #126

Merged
merged 1 commit into from
Feb 13, 2024

Conversation

SeanReece
Copy link
Contributor

Description

Closes #121

By removing sourceMaps, the size of @fastify/swagger-ui package is reduced by ~2.7MB.

This PR modifies prepare-swagger-ui.js to not bundle .map files, but also removes the source map annotation from the source files so browsers do not attempt to retrieve the sourceMaps.

Please see the Source Map SPEC for the definition of the sourceMap annotations we are removing.

The annotation comments are slightly different for js/css, and I'm using a regex to handle both cases

  • Js: //# sourceMappingURL=swagger-ui.js.map
  • css: /*# sourceMappingURL=swagger-ui.css.map*/

image

Build performance

I was worried searching/removing the annotations from the source files would be quite slow but there does not seem to be a performance impact.

Before
image image
After
image image

Checklist

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Collaborator

@Uzlopak Uzlopak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

@mcollina mcollina merged commit 77a7c73 into fastify:master Feb 13, 2024
18 of 21 checks passed
@SeanReece SeanReece deleted the remove-sourcemaps branch February 13, 2024 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Large package size
3 participants