bgrins / TinyColor

Fast, small color manipulation and conversion for JavaScript
https://bgrins.github.io/TinyColor/
MIT License
5.08k stars 438 forks source link

Add Web Worker Feature Detection #141

Closed snorpey closed 1 year ago

snorpey commented 8 years ago

Hey @bgrins,

thank you so much for creating this great library. I'm using it quite a bit in my projects. I just noticed that it wouldn't work properly when imported in a web worker, so I added a feature detection (I chose this one: http://stackoverflow.com/a/18002694 ).

Please let me know what you think. Thank you!

AngryAndConflict commented 7 years ago

Hello @snorpey,

Can you describe your use case, please. I was really exited about web workers since their day of draft-birth, but all my attempts to use them where ruined in piles of inconveniences, code repetition and lack of performance. And I'm looking at tinycolor code, and it seems that the only way it can have practical web worker usage is some crazy, canvas based image\video editor. Seems like only ES7 async functions may save web workers :O(

snorpey commented 7 years ago

@AngryAndConflict you are kind of right about the usecase: i'm using tinycolor in a gif generation script. generating gifs without web workers blocks the main thread and renders the page pretty much unusable (unresponsive to user input) for the duration of the process.

as for my opinion about web worker performance: i think if used correctly, they can have a massive performance impact, especially on low-powered / mobile devices. e.g: http://www.pocketjavascript.com/blog/2015/11/23/introducing-pokedex-org

AngryAndConflict commented 7 years ago

@snorpey thank you for sharing. On mobile, web workers will ruin the network, unless it is on wide wi-fi or async functions are supported. Because worker should have standalone js file to initialize... that also hit the battery. And stuff like low-powered device and limited bandwith always walks together. Also amount of accessable threads not only limited, it is also not predicted and will be "simulated" if device is busy on background, also the casual case for mobiles.

bgrins commented 1 year ago

(6 years later, sorry about that). I think this should be fixed now with the introduction of ESM and using rollup for generating the UMD header: https://github.com/bgrins/TinyColor/pull/245 & https://github.com/bgrins/TinyColor/blob/fa3aa2cb9c9511672efc62926a29d16826bddef5/tinycolor.js#L5-L8