minify javascript with c# - Stack Overflow

I want to minimize javascript in C#. Take for example this javascript I found at: (function (skillet,

I want to minimize javascript in C#. Take for example this javascript I found at: /

(function (skillet, $, undefined) {
        //Private Property
        var isHot = true;

        //Public Property
        skillet.ingredient = "Bacon Strips";

        //Public Method
        skillet.fry = function () {
            var oliveOil;

            addItem("\t\n Butter \n\t");
            addItem(oliveOil);
            console.log("Frying " + skillet.ingredient);
        };

        //Private Method
        function addItem(item) {
            if (item !== undefined) {
                console.log("Adding " + $.trim(item));
            }
        }
    } (window.skillet = window.skillet || {}, jQuery));

Is there any simple C# method I could write to minimize this to one line, removing whitespace etc? I want to right something custom to do this rather than using Minifer or Yahoo.

I want to minimize javascript in C#. Take for example this javascript I found at: http://enterprisejquery./2010/10/how-good-c-habits-can-encourage-bad-javascript-habits-part-1/

(function (skillet, $, undefined) {
        //Private Property
        var isHot = true;

        //Public Property
        skillet.ingredient = "Bacon Strips";

        //Public Method
        skillet.fry = function () {
            var oliveOil;

            addItem("\t\n Butter \n\t");
            addItem(oliveOil);
            console.log("Frying " + skillet.ingredient);
        };

        //Private Method
        function addItem(item) {
            if (item !== undefined) {
                console.log("Adding " + $.trim(item));
            }
        }
    } (window.skillet = window.skillet || {}, jQuery));

Is there any simple C# method I could write to minimize this to one line, removing whitespace etc? I want to right something custom to do this rather than using Minifer or Yahoo.

Share Improve this question asked Jun 30, 2011 at 0:15 amateuramateur 44.7k72 gold badges196 silver badges326 bronze badges 7
  • 8 @amateur: Why roll your own when there are so many existing solutions that work well? – Andrew Whitaker Commented Jun 30, 2011 at 0:18
  • 1 I don't want to use a 3rd party solution but just want something simple and basic. – amateur Commented Jun 30, 2011 at 0:32
  • 3 @amateur: Unless you have a contractual obligation not to use third-party libraries I don't see why you'd want to develop something that already exists, is tested, has active munity support, etc etc. – Yuck Commented Jun 30, 2011 at 0:51
  • @amateur: unless this is your homework... – Rodrigo Commented Jun 30, 2011 at 1:04
  • 1 @Rodrigo, I do when I get an acceptable answer to questions. Thanks for your concern... – amateur Commented Jun 30, 2011 at 8:38
 |  Show 2 more ments

2 Answers 2

Reset to default 6

Douglas Crockford's JSMin.cs

Don't reinvent the wheel, please.

To straight up answer your question yes there is a pretty simple method you can write. Just look at the string one character at a time and see if it's something you want to keep or not. Once you've got that working start a look ahead. By this I mean your going to need to look forward say when you get a " till you get another " and not do anything to the text between the two quotes, do the same thing with ments and what not and your good to go.

There are lots of open source things out there where you can look at the code to find this. http://www.crockford./javascript/jsmin.html (c++ but concept should be the same) http://blog.andrewreitz./2011/07/web-minifier-c.html to name a few

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745646151a4637983.html

相关推荐

  • minify javascript with c# - Stack Overflow

    I want to minimize javascript in C#. Take for example this javascript I found at: (function (skillet,

    3小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信