WebPagetest Forums
Avoid gzip on images with query string - Printable Version

+- WebPagetest Forums (https://www.webpagetest.org/forums)
+-- Forum: Web Performance (/forumdisplay.php?fid=3)
+--- Forum: Optimization Discussions (/forumdisplay.php?fid=5)
+--- Thread: Avoid gzip on images with query string (/showthread.php?tid=10596)



Avoid gzip on images with query string - Joel - 02-14-2012 04:22 AM

Hi,

I know it's not recommended to gzip images (not sure exactly why though) so I used this code in the httpd config file to gzip everything besides images
Code:
<Location />
# Insert filter
SetOutputFilter DEFLATE

# Netscape 4.x has some problems...
BrowserMatch ^Mozilla/4 gzip-only-text/html

# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip

# MSIE masquerades as Netscape, but it is fine
# BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

# NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
# the above regex won't work. You can use the following
# workaround to get the desired effect:
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html

# Don't compress images
SetEnvIfNoCase Request_URI \
\.(?:gif|jpe?g|png)$ no-gzip dont-vary

# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
</Location>

Everything seems to be working fine, however; I just noticed that images with query strings (like /sample.php?id=123456.jpg) are in fact being gziped (See Results)

is there any way I can filter these out?

Thanks


RE: Avoid gzip on images with query string - pmeenan - 02-14-2012 11:12 PM

You shouldn't gzip images because they will actually end up larger - they are already compressed by algorithms at least as good as gzip.

I'm a little curious why you have gzip enabled on everything by default and then choose to disable it under certain circumstances. I'm used to seeing it enabled by mime type:

Code:
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/plain    
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE application/xhtml+xml
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE text/xml    
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE text/javascript
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/x-javascript
    AddOutputFilterByType DEFLATE application/json
</IfModule>



RE: Avoid gzip on images with query string - Joel - 02-15-2012 02:32 AM

Thanks Pat,

I took the code from Apache.org thinking it's the best source...

Thanks for the code, can this one be used as is in the httpd config file, or only in .htaccess?

Smile


RE: Avoid gzip on images with query string - pmeenan - 02-16-2012 12:12 AM

It should work fin in the httpd config file as well - http://httpd.apache.org/docs/2.2/mod/core.html#addoutputfilterbytype


RE: Avoid gzip on images with query string - Joel - 02-16-2012 05:17 AM

using the code you wrote above didn't work first in httpd config, I changed its location to go after
Code:
LoadModule deflate_module modules/mod_deflate.so
(below all LoadModules) and it works fine now!
Thanks


RE: Avoid gzip on images with query string - Joel - 03-01-2012 03:25 AM

if I use the code you provided above; should a file like this "/sample.php?id=file-name.jpg" not be gzipped?

I tried it but it still gzips everythingHuh

it's obviously not being treated like a regular jpg file, because if it was it would have not been gzipped even with my original code
but live headers shows it as a regular image/jpeg

any idea how to fix this?


RE: Avoid gzip on images with query string - pmeenan - 03-06-2012 04:45 AM

Any chance your php code is doing the gzip? Just stretching here because the sample I use doesn't gzip images when I use it but something else is going on since your images are being served from php.


RE: Avoid gzip on images with query string - Joel - 03-06-2012 05:04 AM

we do not gzip with php, the images are in a folder like this /images/12345.jpg then being modified on the fly with php (adding watermark/resizing/etc.) and called with the php ?id=12345.jpg which serves the modified version


RE: Avoid gzip on images with query string - allogarage - 03-10-2012 04:03 AM

Are you sending the correct mime type in your php script?
Code:
header("Content-type: image/jpeg");



RE: Avoid gzip on images with query string - Joel - 03-13-2012 08:54 AM

(03-10-2012 04:03 AM)allogarage Wrote:  Are you sending the correct mime type in your php script?
Code:
header("Content-type: image/jpeg");

Yes, does not seem to help...