rspivak / slimit

SlimIt - a JavaScript minifier/parser in Python
MIT License
551 stars 94 forks source link

Specify certain tokens that cannot be mangled #63

Open ddevault opened 10 years ago

ddevault commented 10 years ago

I get a significant improvement by mangling the JS, but there are a couple of special functions that cannot lose their names.

programmin1 commented 10 years ago

What do you mean? Slimit should mangle only non-globally-accessible function names and variables. So functions that you don't want accessed will be mangled, you can just wrap in IIFE: http://benalman.com/news/2010/11/immediately-invoked-function-expression/

ddevault commented 10 years ago

Ah, here's the thing. I'm using web workers. I'm moving the name of internal functions, as strings, between the UI and the worker.

programmin1 commented 10 years ago

Sounds interesting. Can you provide an example?

ddevault commented 10 years ago

Here's the worker in question (it's in CoffeeScript): https://github.com/MediaCrush/MediaCrush/blob/master/scripts/worker.coffee

The worker can post messages back with execute, which contains code to be executed on the UI thread: https://github.com/MediaCrush/MediaCrush/blob/master/scripts/home.coffee#L129

This is used, for example, here: https://github.com/MediaCrush/MediaCrush/blob/master/scripts/home.coffee#L217 to run a callback after the worker finishes computing a hash.

programmin1 commented 10 years ago

Slimit minifies .coffee?

ddevault commented 10 years ago

No, it's compiled before it's given to slimit. https://github.com/MediaCrush/MediaCrush/blob/master/app.py#L38