minify-kohana icon indicating copy to clipboard operation
minify-kohana copied to clipboard

File corrupted while using gzip encode method

Open petr-g opened this issue 10 years ago • 18 comments
trafficstars

Hi there, I have a trouble with gzip encoding.

When I set

'encodeMethod' => '',

everything works just fine.

But when I set

'encodeMethod' => NULL,    // automatic encoding

the compressed file is corrupted.

This behaviour is not only my local dev-server, but also on the production server, so I beleive this is not happening thanks to my dev-server settings.

After downloading the file via the browser while encoding is set to NULL, the incomming file is corrupted at the end and it final size (after downloading and saving on the disc) is lower then the file without encoding.

Here are the headers:

encoded: headers not ok

not encoded: headers ok

The older PHP version is not the reason. I have 5.6.14 on my production server and the issue is the same there.

I also wanted to attach both CSS versions as an example, but GitHub has not managed to upload my TXT files with uknown reason (it says "Something went really wrong, and we can’t process that file."). Even the MS Word version has not helped.

My Kohana version is 3.3.3.1.

Is there any chance you could help me with this issue?

Thanks, Pert

petr-g avatar Oct 07 '15 21:10 petr-g

hello, can you please verify if it's any of those issues at fault?

https://github.com/mrclay/minify/issues?q=is%3Aissue+encodeMethod+is%3Aclosed

pocesar avatar Oct 07 '15 22:10 pocesar

No, I don't think so. I believe this is another issue.

petr-g avatar Oct 07 '15 23:10 petr-g

P.S.: At this time I use your recomended version of minify vendor: https://github.com/mrclay/minify/tree/db7fe244932ea77cf1438965693672ea12b33da8

petr-g avatar Oct 07 '15 23:10 petr-g

I guess it deserves an upgrade then, since version 2.2 was released last year.

pocesar avatar Oct 08 '15 04:10 pocesar

OK, I haven't known it is possible :-)

Your solution was ready to use. I could only download the sources and run.

With the latest version of minfy it needs to set up the project dependencies = to have some shell, composer etc. This is not so clear for me a s Windows user :-)

Is there any chance a quick help how to upgrade the Minify in my case?

Thanks.

petr-g avatar Oct 08 '15 15:10 petr-g

I managed to install the dependencies ;-) But the latest minify version is not compatible with this version of minify-kohana, so I am stuck.

petr-g avatar Oct 08 '15 23:10 petr-g

yeah, I'll upgrade the dependency and fix the code, since I use this module everywhere in my Kohana projects as well

pocesar avatar Oct 09 '15 01:10 pocesar

Great news, thank you!

petr-g avatar Oct 09 '15 15:10 petr-g

Hi there. Any news? :-) Have you managed to updated the dependency? Thank you for your reply.

html-koder-com avatar Mar 02 '16 22:03 html-koder-com

See if the code in the master branch works for you.

pocesar avatar Mar 02 '16 23:03 pocesar

It's unfortunately still the same. When I open /min/css the browser says the file is not valid or using unsupported compression method.

html-koder-com avatar Mar 03 '16 10:03 html-koder-com

ok, so maybe the problem is a double compression. make sure that PHP and Apache isn't gzipping the output at the same time

pocesar avatar Mar 03 '16 19:03 pocesar

Thank you. I found out it's a Kohana problem. When I serve the static HTML file or PHP file without Kohana, gzip works fine. But the ouput made by Kohana is not "gziped". Unfortunately I have no idea why. Anyway... it is not Minify issue. Thanks.

html-koder-com avatar Mar 03 '16 20:03 html-koder-com

Update: When I use the Kohana without Minify module (remove it from the bootstrap), the gzip works fine. Strange :-)

html-koder-com avatar Mar 03 '16 21:03 html-koder-com

can you show me your application/config/minify.php? If you are using Apache, does adding this to the .htaccess helps?

<IfModule mod_env.c>
# In case AddOutputFilterByType has been added
SetEnv no-gzip
</IfModule>

you can also see if changing the setting to makes anything difference:

return [
   'serveOptions' => [
       'minifierOptions' => [
           'text/css' => [ 'compress' => false ],
       ]
   ]
]

pocesar avatar Mar 03 '16 22:03 pocesar

Here it is:

return array(
    'serveOptions' => array(
        'encodeMethod' => '',
    ),
    'groupsConfig' => array(
        'js'  => array(
            '//resyst/assets/js/resyst-frontend.js',
            '//resyst/assets/js/resyst-popup.js',
            '//assets/js/js.min.js',
        ),
        'css' => array(
            '//assets/css/screen.css',
            '//resyst/assets/css/resyst-popup.css',
        ),
    ),
);

It is also strange that after this module is loaded, all files (including HTML served by Kohana) are without any compression.

When I set the "encodeMethod" to NULL (automatic), the assets are not working as I wrote before.

If I "hack" the module and delete the

ini_set('zlib.output_compression', '0');

in your init.php file, the assets (and compression) are working, but it takes about 10 seconds to render the site (and 9 seconds the browser is waiting on the assest). Without Minify the site is rendered about 0,5 s

html-koder-com avatar Mar 03 '16 22:03 html-koder-com

usually the initial cache takes a lot of time, and subsequent requests work faster. is it the case?

it's weird that removing a setting that disables zlib compression would make it work, because the code is manually gzipped inside minify. maybe new versions of PHP changed something that I'm unaware of

Would be interesting to watch for 'hidden' compressions toggles in php_info(); output as well

pocesar avatar Mar 03 '16 22:03 pocesar

It is slow for every reload of the page. Maybe it is some webhosting issue...

html-koder-com avatar Mar 03 '16 22:03 html-koder-com