Title: plugin super minify
Last modified: August 3, 2021

---

# plugin super minify

 *  Resolved [Ocio132](https://wordpress.org/support/users/ocio132/)
 * (@ocio132)
 * [4 years, 10 months ago](https://wordpress.org/support/topic/plugin-super-minify/)
 * hello good I have a separate plugin because if not the fast velocity minify does
   not work well enough
 *     ```
       <?php
       /**
        * Plugin Name: SuperMinify
        * Plugin URI: https://servicios.ayudawp.com/
         * Description: Superminimiza los c贸digos HTML, CSS y JS de tu web y quita los comentarios HTML (excepto los de IE que est茅n dentro de scripts). Totalmente activar y listo. Si no quieres minimizar alg煤n c贸digo utiliza la tag '<!--superminify-html-compression no compression-->'
        * Version: 1.0
        * Author: Fernando Tellado
        * Author URI: https://tellado.es/
        */
       defined( 'ABSPATH' ) || die( 'No script kiddies please!' );
       class superminify_HTML_Compression
       {
               // Ajustes - Cambiar a false para desactivar
               protected $compress_css = true;
               protected $compress_js = false;
               protected $info_comment = true;
               protected $remove_comments = true;
   
               // Variables
               protected $html;
   
               public function __construct($html)
               {
                       if (!empty($html))
                       {
                               $this->parseHTML($html);
                       }
               }
   
               public function __toString()
               {
                       return $this->html;
               }
   
               protected function minifyHTML($html)
               {
                       $pattern = '/<(?<script>script).*?<\/script\s*>|<(?<style>style).*?<\/style\s*>|<!(?<comment>--).*?-->|<(?<tag>[\/\w.:-]*)(?:".*?"|\'.*?\'|[^\'">]+)*>|(?<text>((<[^!\/\w.:-])?[^<]*)+)|/si';
                       preg_match_all($pattern, $html, $matches, PREG_SET_ORDER);
                       $overriding = false;
                       $raw_tag = false;
                       // Variable reused for output
                       $html = '';
                       foreach ( $matches as $token ) {
   
                               $tag = (isset($token['tag'])) ? strtolower($token['tag']) : null;
                               $content = $token[0];
   
                               if ( is_null( $tag ) ) {
   
                                       if ( !empty( $token['script'] ) ) {
   
                                               $strip = $this->compress_js;
   
                                       } else if ( !empty($token['style'] ) ) {
   
                                               $strip = $this->compress_css;
   
                                       } else if ( $content == '<!--superminify-html-compression no compression-->' ) {
   
                                               $overriding = !$overriding;
                                               // Don't print HTML comments
                                               continue;
   
                                       } else if ( $this->remove_comments ) {
   
                                               if ( !$overriding && $raw_tag != 'textarea' ) {
   
                                                       // Remove any HTML comment, except those conditional for MSIE
                                                       $content = preg_replace('/<!--(?!\s*(?:\[if [^\]]+]|<!|>))(?:(?!-->).)*-->/s', '', $content);
                                               }
                                       }
   
                               } else {
   
                                       if ( $tag == 'pre' || $tag == 'textarea' || $tag == 'script' ) {
   
                                               $raw_tag = $tag;
   
                                       } else if ( $tag == '/pre' || $tag == '/textarea' || $tag == '/script' ) {
   
                                               $raw_tag = false;
   
                                       } else {
   
                                               if ($raw_tag || $overriding) {
   
                                                       $strip = false;
   
                                               } else {
   
                                                       $strip = true;
   
                                                       // Remove any empty attribute except:
                                                       // action, alt, content, src
                                                       $content = preg_replace('/(\s+)(\w++(?<!\baction|\balt|\bcontent|\bsrc)="")/', '$1', $content);
   
                                                       // Remove any space before the end of any closing XHTML tag
                                                       // JavaScript excluded
                                                       $content = str_replace(' />', '/>', $content);
                                               }
   
                                       }
   
                               }
   
                               if ( $strip ) {
   
                                       $content = $this->removeWhiteSpace($content);
                               }
   
                               $html .= $content;
                       }
   
                       return $html;
               }
   
               public function parseHTML($html)
               {
                       $this->html = $this->minifyHTML($html);
               }
   
               protected function removeWhiteSpace($str)
               {
                       $str = str_replace( "\t", ' ', $str );
                       $str = str_replace( "\n",  '', $str );
                       $str = str_replace( "\r",  '', $str );
   
                       while ( stristr($str, '  ' ) ) {
   
                               $str = str_replace('  ', ' ', $str);
                       }
   
                       return $str;
               }
       }
   
       function superminify_html_compression_finish($html) {
   
               return new superminify_HTML_Compression($html);
       }
   
       function superminify_html_compression_start() {
   
               ob_start( 'superminify_html_compression_finish' );
       }
   
       add_action( 'get_header', 'superminify_html_compression_start' );
       ```
   
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fplugin-super-minify%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 1 replies (of 1 total)

 *  Thread Starter [Ocio132](https://wordpress.org/support/users/ocio132/)
 * (@ocio132)
 * [4 years, 10 months ago](https://wordpress.org/support/topic/plugin-super-minify/#post-14729030)
 * in the end I have changed everything for assen clean up

Viewing 1 replies (of 1 total)

The topic ‘plugin super minify’ is closed to new replies.

 * ![](https://ps.w.org/fast-velocity-minify/assets/icon-128x128.jpg?rev=1440946)
 * [Fast Velocity Minify](https://wordpress.org/plugins/fast-velocity-minify/)
 * [Support Threads](https://wordpress.org/support/plugin/fast-velocity-minify/)
 * [Active Topics](https://wordpress.org/support/plugin/fast-velocity-minify/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/fast-velocity-minify/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/fast-velocity-minify/reviews/)

 * 1 reply
 * 1 participant
 * Last reply from: [Ocio132](https://wordpress.org/support/users/ocio132/)
 * Last activity: [4 years, 10 months ago](https://wordpress.org/support/topic/plugin-super-minify/#post-14729030)
 * Status: resolved