asgardeo / asgardeo-auth-react-sdk

To maintain the implementation of Asgardeo React authentication SDK
Apache License 2.0
40 stars 91 forks source link

bundle size too big for React-SDK #147

Open tmkasun opened 2 years ago

tmkasun commented 2 years ago

Is your suggestion related to an experience? Please describe.

When we did a bundle analysis in our React app which we use @asgardeo/auth-react for auth purposes, It outputs the following result.

image

@asgardeo/auth-react is consuming +500KB which is bigger than the next biggest chunk in our app. For the comparison, MUI core is under 100KB, React + React-DOM is ~126KB

So IMO +500KB for auth library is an unusually large bundle size.

Describe the improvement

IMHO, We might be packing the resources that @asgardeo/auth-react probably not used in the runtime, So if we can do proper Tree shaking we might able to reduce the bundle size by large amount.

pavinduLakshan commented 9 months ago

The reason for this "unusual" large bundle size is that the web worker storage implementation can not be treeshaked, as what will be used by the web worker in the runtime cannot be determined in the build time.

As per the offline ad-hoc conversations we had, there are several ways to address this concern.

  1. Package the web worker implementation as an npm package to be optionally installed, since the SDK's default token storage strategy is session storage.
  2. Provide an option (a build-time argument) to select web worker implementation to be included in the final bundle.

The following are some of the alternative methods I could come up with.

  1. Load the web worker implementation from remote CDN.
  2. Re use the code between main thread client and web worker client using a library such as webworkify [1].

[1] https://github.com/browserify/webworkify

cc: @DonOmalVindula @brionmario