public function domElementAfterMinification(SimpleHtmlDom $element, HtmlMin $htmlMin)
    {
        $attributes = $element->getAllAttributes();
        if ($attributes === null) {
            return;
        }

        $attrs = [];
        foreach ((array) $attributes as $attrName => $attrValue) {

            // -------------------------------------------------------------------------
            // Remove optional "http:"-prefix from attributes.
            // -------------------------------------------------------------------------

            if ($htmlMin->isDoRemoveHttpPrefixFromAttributes()) {
                if (
                    ($attrName === 'href' || $attrName === 'src' || $attrName === 'action')
                    &&
                    !(isset($attributes['rel']) && $attributes['rel'] === 'external')
                    &&
                    !(isset($attributes['target']) && $attributes['target'] === '_blank')
                ) {
                    $attrValue = \str_replace('http://', '//', $attrValue);
                }
            }

            if ($this->removeAttributeHelper($element->tag, $attrName, $attrValue, $attributes, $htmlMin)) {
                $element->{$attrName} = null;

                continue;
            }

            // -------------------------------------------------------------------------
            // Sort css-class-names, for better gzip results.
            // -------------------------------------------------------------------------

            if ($htmlMin->isDoSortCssClassNames()) {
                $attrValue = $this->sortCssClassNames($attrName, $attrValue);
            }

            if ($htmlMin->isDoSortHtmlAttributes()) {
                $attrs[$attrName] = $attrValue;
                $element->{$attrName} = null;
            }
        }

        // -------------------------------------------------------------------------
        // Sort html-attributes, for better gzip results.
        // -------------------------------------------------------------------------

        if ($htmlMin->isDoSortHtmlAttributes()) {
            \ksort($attrs);
            foreach ($attrs as $attrName => $attrValue) {
                $attrValue = HtmlDomParser::replaceToPreserveHtmlEntities($attrValue);
                $element->setAttribute($attrName, $attrValue, true);
            }
        }
    }