I am attempting to make a javascript library which I would prefer to be compatible with both browsers and node. However, there is some functionality offered in the node API that isn't offered in browsers (such as compression). I know it would be possible to code this functionality in javascript so it would be cross-compatible, but the node native compression will probably perform much better as it is much lower level.
How should I split between browser-compatible code and code that uses node API?
The way I see it, I could do one of the following:
- make 2 separate scripts, one for node and one for browsers
- make my code figure out the environment it is in and act accordingly
- make all my code the same, but lose some performance improvements I would have had in node
What should I do to solve this?