supertokens-auth-react icon indicating copy to clipboard operation
supertokens-auth-react copied to clipboard

Large Bundle size

Open jeremylynch opened this issue 2 years ago • 2 comments

This is a great product and library. However my main criticism is the bundle size.

Supertokens-auth-react: 590kb libphonenumber: 350kb react-phone-number-input: 212kb supertokens-website: 133kb chroma: 97kb emotion 69kb

image

Combined this is well over 1mb for the entire library.

A few questions:

  1. Are we able to optionally drop libphonenumber/react-phone-number-input ? We are only using one country code and do not need this.
  2. Are we able to drop chroma?
  3. Is there a way we can delay loading the supertokens scripts to mitigate impact on performance?

jeremylynch avatar May 08 '22 13:05 jeremylynch

hey @jeremylynch the supertokens-auth-react SDK is split into different recipes which have their own size limits. Furthermore, the production, minified build for supertokens-website is 10kb. Is the above screenshot from a dev build?

At the moment, the initialisation of supertokens is done statically - this means that you must import from all the recipes you want to use upfront - this increases the bundle size.

We can explore an API change to make this more dynamic. But this will probably take a while.. For now, what you can do is to call supertokens.init with a different config based on which page is being loaded in your app. For example, on most pages of your app, you would need only the Session recipe (assuming you use the SessionAuth and not EmailPasswordAuth or PasswordlessAuth), then on those pages, you can initialise the recipeList with the session recipe and nothing more. For the login pages, you can use the EmailPassword and Passwordless recipe.

This would of course require your app to not be an SPA, or at least not be an SPA for the login pages only. Anyhow, I do see this as a problem and we can work on solving this.

Are we able to optionally drop libphonenumber/react-phone-number-input ? We are only using one country code and do not need this. Are we able to drop chroma?

Not easily. You can always fork the repo and make the change in the code yourself though.

Is there a way we can delay loading the supertokens scripts to mitigate impact on performance?

I think my initial paragraph answers this question.


If this is a deal breaking issue for you, you can always build your own UI and use just the supertokens-website SDK for session management - that should be ~10kb for production build

rishabhpoddar avatar May 08 '22 15:05 rishabhpoddar

Are you referring to the "stat size" that the bundle size analyzer gives? That is taken before minification and , please check the parsed/gzipped sizes. Parsed size is the one that affects startup time and the Gzip size is representative of the amount of data that is transferred over the network.

porcellus avatar May 13 '22 12:05 porcellus

Contributor

https://bundlephobia.com/package/[email protected]

Seeing red on bundle analyzer gives me panic attacks. Thanks.

BrycensRanch avatar Nov 19 '22 21:11 BrycensRanch

hey @BrycensRanch we are in the process of getting rid of the emotion dependency which forms a huge part of the bundle size. Should be done within the next month.

rishabhpoddar avatar Nov 20 '22 05:11 rishabhpoddar

It's done. The work is done

Romvnly-Gaming avatar Jan 24 '23 21:01 Romvnly-Gaming

please use version >= 0.30.0

rishabhpoddar avatar Jan 25 '23 07:01 rishabhpoddar