twilio-taskrouter.js icon indicating copy to clipboard operation
twilio-taskrouter.js copied to clipboard

bundle size

Open mfulton26 opened this issue 1 year ago • 2 comments

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

mfulton26 avatar May 13 '24 12:05 mfulton26

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.

AndreyTwilio avatar May 14 '24 13:05 AndreyTwilio

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.

mfulton26 avatar May 14 '24 13:05 mfulton26