Пример #1
0
        void TrimScriptOrStyle(HtmlElement element, HtmlScriptStyleElement type)
        {
            if (settings.RemoveScriptStyleTypeAttribute && type != HtmlScriptStyleElement.JSON)
            {
                element.RemoveAttribute("type");
            }

            if (type != HtmlScriptStyleElement.Style && !settings.MinifyJs)
            {
                return;
            }

            if (type == HtmlScriptStyleElement.Style && !settings.MinifyCss)
            {
                return;
            }

            var raw = element.FirstChild as HtmlRaw;

            if (raw == null)
            {
                return;
            }

            var slice = raw.Slice;

            slice.TrimStart();
            slice.TrimEnd();

            // If the text has a comment or CDATA, we won't try to minify it
            if (slice.StartsWith("<!--") || slice.StartsWithIgnoreCase("<![CDATA["))
            {
                return;
            }

            var text = slice.ToString();

            var textMinified = MinifyJsOrCss(text, type);

            if (textMinified == null)
            {
                return;
            }

            raw.Slice = new StringSlice(textMinified);
        }
Пример #2
0
        void TrimScriptOrStyle(HtmlElement element, bool isJs)
        {
            // We remove the type attribute, as it default to text/css and text/javascript
            if (settings.RemoveScriptStyleTypeAttribute)
            {
                element.RemoveAttribute("type");
            }

            if ((isJs && !settings.MinifyJs) || (!isJs && !settings.MinifyCss))
            {
                return;
            }

            var raw = element.FirstChild as HtmlRaw;

            if (raw == null)
            {
                return;
            }

            var slice = raw.Slice;

            slice.TrimStart();
            slice.TrimEnd();

            // If the text has a comment or CDATA, we won't try to minify it
            if (slice.StartsWith("<!--") || slice.StartsWithIgnoreCase("<![CDATA["))
            {
                return;
            }

            var text = slice.ToString();

            var textMinified = MinifyJsOrCss(text, isJs);

            if (textMinified == null)
            {
                return;
            }

            raw.Slice = new StringSlice(textMinified);
        }