andrewdavey / cassette

Manages .NET web application assets (scripts, css and templates)
http://getcassette.net
MIT License
534 stars 143 forks source link

obfuscate option? #282

Open DrZim opened 12 years ago

DrZim commented 12 years ago

Any way to add an obfuscate option for javascript? (I looked fairly well for this option so I apologize if I missed it.)

andrewdavey commented 12 years ago

Do you mean to minify JavaScript? Or do you mean actually obfuscate?

DrZim commented 12 years ago

It appears to minify already. I do mean obfuscate. Any docs on how to add this to it (or maybe have it part of the project?)

andrewdavey commented 12 years ago

Assuming you're on the v2 branch (it's in beta, soon to be released)...

Implement the IAssetTransformer interface and add your obfuscation code (you'll find examples of this throughout the Cassette code e.g. https://github.com/andrewdavey/cassette/blob/v2/src/Cassette/Stylesheets/ExpandCssUrlsAssetTransformer.cs ).

This transformer can then be added to assets using a Bundle processor. See https://github.com/andrewdavey/cassette/blob/v2/src/Cassette/BundleProcessing/AddTransformerToAssets.cs for an example IBundleProcessor base class that does this.

You will probably want to add an extension method to make it easy to use your obfuscator. See https://github.com/andrewdavey/cassette/blob/v2/src/Cassette/Stylesheets/StylesheetBundleExtensions.cs for ideas.

The end result will be something like:

bundles.Add<ScriptBundle>("scripts", b => b.Obfuscate());
dotnetchris commented 12 years ago

FWIW combined and minified javascript is pretty damn obfuscated already!