开发者

minify javascript with c#

开发者 https://www.devze.com 2023-03-16 20:16 出处:网络
I want to minimize javascript in C#. Take for example this javascript I found at: http://enterprisejquery.com/2010/10/how-good-c-habits-can-encourage-bad-javascript-habits-part-1/

I want to minimize javascript in C#. Take for example this javascript I found at: http://enterprisejquery.com/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.


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 comments 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.com/javascript/jsmin.html (c++ but concept should be the same) http://blog.andrewreitz.com/2011/07/web-minifier-c.html to name a few

0

精彩评论

暂无评论...
验证码 换一张
取 消