Welcome Guest, Not a member yet? Register   Sign In
Why was the minifier removed?
#1

(This post was last modified: 12-22-2014, 06:06 AM by spjonez.)

Why was minification support removed? https://github.com/bcit-ci/CodeIgniter/pull/2795

I've been using this in production for almost a year. I haven't been using the built in regex since it didn't work with inline-block layouts that require no spaces between elements (I posted mine in that ticket). While I can add it back myself it seems odd to remove a feature like this.

This is my extended method, it minifies all HTML and ignores inline JS so it's completely safe:

Code:
    public function minify( $output, $type = 'text/html' ) {

        if ( $type == 'text/html' ) {
            if ( strlen( $output ) === 0 ) {
                return '';
            }

            $size_before = strlen( $output );

            if ( $output[ 0 ] == '{' || $output[ 0 ] == '[' ) {
                $json = json_decode( $output );

                if ( json_last_error( ) == JSON_ERROR_NONE ) {
                    if ( is_object( $json ) && property_exists( $json, 'view' ) ) {
                        $json->view = preg_replace( '/(?:(?<=\>)|(?<=\/\>))(\s+)(?=\<\/?)/', '', $json->view );
                    }

                    $output = json_encode( $json );
                }
                else {
                    $output = preg_replace( '/(?:(?<=\>)|(?<=\/\>))(\s+)(?=\<\/?)/', '', $output );
                }
            }
            else {
                $output = preg_replace( '/(?:(?<=\>)|(?<=\/\>))(\s+)(?=\<\/?)/', '', $output );
            }

            $size_removed = $size_before - strlen( $output );
            $savings_percent = round( ( $size_removed / $size_before ) * 100 );

            log_message( 'debug', 'Minifier shaved ' . ( $size_removed / 1000 ) . 'KB (' . $savings_percent . '%) off final HTML output.' );
        }
        else {
            $output = parent::minify( $output, $type );
        }

        return $output;
    }
Reply
#2

(12-22-2014, 06:02 AM)spjonez Wrote: Why was minification support removed? https://github.com/bcit-ci/CodeIgniter/pull/2795

I've been using this in production for almost a year. I haven't been using the built in regex since it didn't work with inline-block layouts that require no spaces between elements (I posted mine in that ticket). While I can add it back myself it seems odd to remove a feature like this.

This is my extended method, it minifies all HTML and ignores inline JS so it's completely safe:


Code:
    public function minify( $output, $type = 'text/html' ) {

        if ( $type == 'text/html' ) {
            if ( strlen( $output ) === 0 ) {
                return '';
            }

            $size_before = strlen( $output );

            if ( $output[ 0 ] == '{' || $output[ 0 ] == '[' ) {
                $json = json_decode( $output );

                if ( json_last_error( ) == JSON_ERROR_NONE ) {
                    if ( is_object( $json ) && property_exists( $json, 'view' ) ) {
                        $json->view = preg_replace( '/(?:(?<=\>)|(?<=\/\>))(\s+)(?=\<\/?)/', '', $json->view );
                    }

                    $output = json_encode( $json );
                }
                else {
                    $output = preg_replace( '/(?:(?<=\>)|(?<=\/\>))(\s+)(?=\<\/?)/', '', $output );
                }
            }
            else {
                $output = preg_replace( '/(?:(?<=\>)|(?<=\/\>))(\s+)(?=\<\/?)/', '', $output );
            }

            $size_removed = $size_before - strlen( $output );
            $savings_percent = round( ( $size_removed / $size_before ) * 100 );

            log_message( 'debug', 'Minifier shaved ' . ( $size_removed / 1000 ) . 'KB (' . $savings_percent . '%) off final HTML output.' );
        }
        else {
            $output = parent::minify( $output, $type );
        }

        return $output;
    }

I believe I read somewhere on git that it was causing issues with certain things. We all know CI 3.0 is practically ready to roll out but there's always a risk in running it in production before it's released.
Reply
#3

(This post was last modified: 12-23-2014, 05:54 AM by spjonez.)

(12-22-2014, 10:02 PM)albertleao Wrote: I believe I read somewhere on git that it was causing issues with certain things. We all know CI 3.0 is practically ready to roll out but there's always a risk in running it in production before it's released.

That's what I'm confused about. The regex I'm using came from a proprietary framework I helped develop and was used in 50+ production websites before I left the company. They're still using it and have built another 50-100 sites with it. I've been using it in my CI app as well with no issues. All of the examples linked in the ticket are either poor code or edge cases that shouldn't be in a production website anyway.

Most of the problems with the original implementation are around attempting to minify inline JS. My code ignores those since generally you only have a few lines anyway if you're writing modular JS.

If you want to build responsive inline-block layouts minification is necessary! IMO floats are the devil and should be discouraged in modern web design.
Reply
#4

I've left a quite descriptive commit message on this and it is linked at the end of the pull request that you posted here ... And really, how surprising can that be if you've modified it yourself already? Smile
Reply
#5

(This post was last modified: 12-27-2014, 11:13 AM by spjonez.)

(12-24-2014, 06:15 PM)Narf Wrote: I've left a quite descriptive commit message on this and it is linked at the end of the pull request that you posted here ... And really, how surprising can that be if you've modified it yourself already? Smile

Did you try the one I posted in that PR? It doesn't have any of the issues you linked...
Reply
#6

(12-27-2014, 11:13 AM)spjonez Wrote:
(12-24-2014, 06:15 PM)Narf Wrote: I've left a quite descriptive commit message on this and it is linked at the end of the pull request that you posted here ... And really, how surprising can that be if you've modified it yourself already? Smile

Did you try the one I posted in that PR? It doesn't have any of the issues you linked...

The very first reply to your PR was a list of issues that it has and you didn't do anything to fix them. I could criticize the same PR in other directions as well, but it's pointless ... the feature is removed and that's it. I've linked an alternative library in the commit message - use it.
Reply
#7

It sucks that improper code (comment example in that PR) is preventing useful features from being implemented. I understand your reasoning though.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB