Reputation: 1086
Google tell us here, that:
"...gzipping is only beneficial for larger resources. Due to the overhead and latency of compression and decompression, you should only gzip files above a certain size threshold; we recommend a minimum range between 150 and 1000 bytes. Gzipping files below 150 bytes can actually make them larger."
I currently use
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
in my .htaccess. How can I make this only apply to files above 150 bytes?
Thanks.
Upvotes: 2
Views: 2902
Reputation: 2943
The 150 threshold for compression to make sense depends on the content. Files with highly random content don't compress well, if at all. Even if the file size is larger than 150 or much more.
Upvotes: 0
Reputation: 16825
I don't think you will gain anything by trying this. Compression and decompression of these small files is very fast, even on mobile. Furthermore 150bytes is well beneath the normal MTU on the internet, so it will still be only one IP-packet, even if the compression increases it's size.
But since you are using mod_gzip and not mod_deflate you could use the following.
# minimum size (in bytes) for files to be compressed
mod_gzip_minimum_file_size 500
# (for very small files compression will produce only small absolute gains
# [you will still save about 50% of the content, but some additional
# 500 bytes of HTTP and TCP headers will always remain uncompressed],
# but still produce CPU load for both client and server.
# mod_gzip will automatically set smaller values than 300 bytes for
# this directive to exactly this value 300.)
Note that the default value is 300bytes, so your setup is already doing what you want.
Upvotes: 2