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

Reduce bundle size of the SDK and/or make it treeshakable #442

Open
minht11 opened this issue Aug 27, 2024 · 4 comments
Open

Reduce bundle size of the SDK and/or make it treeshakable #442

minht11 opened this issue Aug 27, 2024 · 4 comments

Comments

@minht11
Copy link

minht11 commented Aug 27, 2024

The bundle size of the Iterable SDK minified is 294kb which is very large, some apps are smaller than this.

One way to reduce size of the library would be to make it more treeshable, if for example some feature is not used it could be stripped from the final bundle, maybe they could be opt in, for example if users only use tracking and not notifications and so on.

@minht11
Copy link
Author

minht11 commented Aug 27, 2024

return html
? set(message, 'content.html', wrapWithIFrame(html as string))
: message;
Lodash is huge library, but only used once for set which could be replaced with setting property directly.

Yup library is used in very few places and could easily replaced with https://valibot.dev/ treeskable, very small bundle size alternative

uuid can be replaced with native crypto.generateRandomUUID

Axios could be replaced with native fetch, though that might be breaking change, not quite sure.

@martinmckenna
Copy link
Contributor

martinmckenna commented Aug 27, 2024

This doesn't exist in the current README (but should still be applicable at this time):

https://github.com/Iterable/iterable-web-sdk/blob/221a5b17e09212a7cef437378743b2d4712b3083/README.md#a-note-about-imports

If you import functions from their direct path, your app should only bundle the code you're using.

So this:

import { getInAppMessages } from '@iterable/web-sdk/dist/inapp';

instead of this:

import { getInAppMessages } from '@iterable/web-sdk';

But yeah updating the package.json with sideEffects: false would also enable tree shaking. In the meantime, I'd use that approach tho ^^

@minht11
Copy link
Author

minht11 commented Aug 27, 2024

I am lazily importing Iterable, though I might be impacted by rollup/rollup#5410 bug, my bad about treeshaking part, though there are still low hanging fruits which could be optimized.

@mprew97
Copy link
Contributor

mprew97 commented Sep 9, 2024

Opened a PR to enable tree-shaking here. Will cut a separate ticket for addressing some of the larger packages usage.

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

No branches or pull requests

3 participants