digitalbazaar / http-client

An opinionated, isomorphic HTTP client.
BSD 3-Clause "New" or "Revised" License
2 stars 7 forks source link

Consider lazy loading `ky-universal` #34

Closed dlongley closed 1 year ago

dlongley commented 1 year ago

See: https://github.com/digitalbazaar/jsonld.js/issues/516#issuecomment-1485959372

@Peeja,

Thanks, great analysis!

It seems that a PR to http-client could be made that did something to the internals ... like making _createHttpClient take a function that returned a (possibly memoized) kyPromise rather than taking a promise directly. That would allow the original import of ky-universal to also be moved within that function for the default case where the parent is the original / base ky instance:

https://github.com/digitalbazaar/http-client/blob/v3.3.0/lib/httpClient.js#L35-L51

Unfortunately, it seems this would mean that the kyPromise exported by the library would also need to become such a function, which would be a breaking change. Maybe we can figure out a way around that -- but even if we can't, a major version could be released that avoids the problem you identified.

Any further discussion that relates to http-client specifically should be taken over here: digitalbazaar/http-client#34

dlongley commented 1 year ago

I'm not sure we intended for kyPromise to be a used export (though we didn't underscore-prefix it) ... maybe we exposed it for internal / testing usage only?

Perhaps we'd just make it so that the exported kyPromise would never resolve until some call was made to import ky-universal... which is already true, but we currently always make that call. So what would be changing would be when / what triggers the resolution of that Promise. We may be able to get away with that as a non-breaking change.