twilio / twilio-taskrouter.js

JS SDK v2 for Twilio's TaskRouter skills based routing system.
https://www.twilio.com/docs/taskrouter
Other
23 stars 32 forks source link

bundle size #128

Closed mfulton26 closed 4 days ago

mfulton26 commented 1 month ago

My team is trying to reduce the size of our app and twilio-taskrouter is one of the larger dependencies in the web app. Can efforts be made to reduce the size?

Two opportunities I see are:

  1. Use built-in web fetch API instead of axios (either directly or via a thin wrapper for convenience methods, e.g. ky).
  2. Avoid loading all (or any) of Lodash. Importing functions directly (rather than through _) should allow tree shaking for webpack/rollup/etc. Another option is to use Lodash custom builds. Some or all of the usages can be replaced using modern ES built-ins too. twilio-taskrouter currently only uses 13 methods from lodash (excluding a few other usages in tests/specs):
    1. difference
    2. every
    3. filter
    4. inRange
    5. isBoolean
    6. isDate
    7. isEmpty
    8. isInteger
    9. isNil
    10. isObject
    11. isString
    12. pick
    13. upperFirst
AndreyTwilio commented 1 month ago

Thanks @mfulton26, we will go ahead and integrate proposed change for lodash. However axios dependency is slightly more complex, since we need to make sure this package can work on Mobile using React Native.

mfulton26 commented 1 month ago

Thanks @mfulton26, we will go ahead and integrate proposed change for lodash. However axios dependency is slightly more complex, since we need to make sure this package can work on Mobile using React Native.

Sounds good to me. I think pulling in all of lodash into bundled web apps was my main concern. It does, however, appear that React Native does support the Fetch API: https://reactnative.dev/docs/network. Long term it may be good to move off of axios. (One less dependency to keep up to date, patch for new security vulnerability alerts, etc.)

Thank you.