Current time: 12-06-2019, 03:26 AM Hello There, Guest! (LoginRegister)

Post Reply 
 
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Avoid gzip on images with query string
02-14-2012, 04:22 AM (This post was last modified: 02-14-2012 04:32 AM by Joel.)
Post: #1
Avoid gzip on images with query string
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
Visit this user's website Find all posts by this user
Quote this message in a reply
02-14-2012, 11:12 PM
Post: #2
RE: Avoid gzip on images with query string
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>
Visit this user's website Find all posts by this user
Quote this message in a reply
02-15-2012, 02:32 AM
Post: #3
RE: Avoid gzip on images with query string
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
Visit this user's website Find all posts by this user
Quote this message in a reply
02-16-2012, 12:12 AM
Post: #4
RE: Avoid gzip on images with query string
It should work fin in the httpd config file as well - http://httpd.apache.org/docs/2.2/mod/cor...lterbytype
Visit this user's website Find all posts by this user
Quote this message in a reply
02-16-2012, 05:17 AM
Post: #5
RE: Avoid gzip on images with query string
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
Visit this user's website Find all posts by this user
Quote this message in a reply
03-01-2012, 03:25 AM (This post was last modified: 03-01-2012 03:35 AM by Joel.)
Post: #6
RE: Avoid gzip on images with query string
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?
Visit this user's website Find all posts by this user
Quote this message in a reply
03-06-2012, 04:45 AM
Post: #7
RE: Avoid gzip on images with query string
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.
Visit this user's website Find all posts by this user
Quote this message in a reply
03-06-2012, 05:04 AM
Post: #8
RE: Avoid gzip on images with query string
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
Visit this user's website Find all posts by this user
Quote this message in a reply
03-10-2012, 04:03 AM
Post: #9
RE: Avoid gzip on images with query string
Are you sending the correct mime type in your php script?
Code:
header("Content-type: image/jpeg");
Visit this user's website Find all posts by this user
Quote this message in a reply
03-13-2012, 08:54 AM
Post: #10
RE: Avoid gzip on images with query string
(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...
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)