I have enabled GZIP in cPanel (Software > Optimize Website). It's set to "Compress All Content". GTmetrix speed test reports that one CSS file is not being compressed:
https://www.swphotovideo.com.au/wp-content/cache/min/1/2affb9ab843ac1d569fdadbf67636031.css
Any idea why this might? It's quite large (1mb~) so I'd like to sort it out. GZIP seems to be working for everything else, but this file.
We use GZIP to compress files so that Websites speed will become fast. As your problem shows you are able to compress all other files but not able to compress "CSS" files.
First of all, you should check your .htaccess file and check whether "TEXT/CSS" is there under "mod_deflate" or not.
# BEGIN GZIP
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
</ifmodule>
# END GZIP
Also, to speed up your WordPress website you can use mod_expires to have Browser cache in WordPress which will speed up your website.
You can refer this article to speed up your WordPress application.
https://hoststud.com/resources/tips-to-leverage-browser-caching-in-wordpress.156/
Or, you should ask your hosting provider regarding this issue.
In several nginx tutorial sites explaining "how to set up gzip compression," I've seen this list of MIME types repeated:
gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
However, I immediately found that this list did not result in compression being enabled for JavaScript in Chromium. I had to add application/javascript to the list. Which leads me to believe this list is outdated.
Is there a definitive list of all the content types I would want to gzip?
There is no definitive list of the file types you would want to gzip. Any file type readable as plain text (i.e. non-binary files) are able to be gzipped, and so a "definitive" list would be massive. Therefore, it ultimately depends on which file types you are actually serving, which you can check for any given file via the HTTP Content-Type header.
If you want to be doubly sure you are covering all possible MIME types for a particular extension (which I think is reasonable), Looking at this SO post, this text file contains a pretty darn exhaustive list.
It's important to note that some binary file types like .png and .pdf (even .woff) incorporate compression into the format itself and as such should not be gzipped (because doing so could produce a compressed file larger than the original). My rule of thumb is: if my code editor can't read the file as UTF-8 text, gzipping the file would not be wise (or at least it wouldn't be very efficient).
FWIW, I typically gzip the following formats (in my Apache .htaccess) on my site:
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/xml text/css text/javascript application/javascript application/x-javascript application/json application/xml image/svg+xml
</IfModule>
I have a problem with the inclusion of compression on my website. Site hosted with WordPress and GZIP compression of HTML works fine even without any lines in the .htaccess or plug-ins. But the compression of JS/CSS does not turn on. Ive tried a lot of different codes, such as:
<IfModule mod_deflate.c>
<FilesMatch "\.(html|php|txt|xml|js|css)$">
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>
or
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
or
# compress all text and html:
AddOutputFilterByType DEFLATE text/css application/javascript
or
# Or, compress certain file types by extension:
<Files *.css>
SetOutputFilter DEFLATE
</Files>
<Files *.js>
SetOutputFilter DEFLATE
</Files>
or even in my header.php:
<?php ob_start("ob_gzhandler"); ?> //result - site crahes
and many others....
Communicated with the server administrator, included more apache modificators: mod_headers, mod_filter and mod_expires, but compression still does not work. I can not understand why??? And how compression of HTML works???
Some of my server's phpinfo():
PHP Version 5.3.3-7+squeeze14
Apache Version Apache/2.2.16 (Debian)
Loaded Modules mod_deflate mod_expires mod_filter mod_headers mod_include mod_mime mod_rewrite etc...
HTTP_ACCEPT_ENCODING gzip,deflate,sdch
Accept-Encoding gzip,deflate,sdch
I've tried to use a lot of WP plugins, such as: W3 Total Cache, Force GZIP, WP HTTP compression, etc... And... Nothing!
Then I've tried to compress files manually: style.css -> style.css.gz -rename-> style.css -load to ftp and replace original. Google's PageSpeed says "Great! Compression enabled! Here is your speed points", but my browser says "Where is my style.css and what kind of cr*p is this?" - because response with style.css has no "encoded gsip" header.
Thanks for advise!!!
The solution is quite simple. Problem is in apache configuration: AllowOverride directive.
AllowOverride None
must be changed to:
AllowOverride AuthConfig FileInfo
or just
AllowOverride All
Then, if you want to optimize browser cache
leverage browser caching
and set ExpiresActive on, config your HTTPD.conf to:
AllowOverride AuthConfig FileInfo Indexes
or just
AllowOverride All
The question is, will the hosting administrator account change the settings.....
YSlow is telling me that my css should be compressed, but after several hours of tinkering, I cannot for the life of me get gzip to work for my website. At this point, I'm not even sure if the performance increase (will there be one?) will be worth the effort.
I'm running a WordPress site on a 1&1 shared hosting account.
Honestly, I don't really know what I'm doing with this stuff, and can't seem to get an appropriate setup. I read in a few places that with 1&1, "modules Apache mod_deflate and mod_gzip are not installed.", so I assume this is part of the problem.
I have tried the following code:
This one doesn't seem to do anything:
<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>
This causes a 500 error
<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
# 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>
This (from html5 boilerplate) doesn't seem to do anything either:
<IfModule mod_deflate.c>
# Force deflate for mangled headers developer.yahoo.com/blogs/ydn/posts/2010/12/pushing-beyond-gzipping/
<IfModule mod_setenvif.c>
<IfModule mod_headers.c>
SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
</IfModule>
</IfModule>
# HTML, TXT, CSS, JavaScript, JSON, XML, HTC:
<IfModule filter_module>
FilterDeclare COMPRESS
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/html
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/css
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/plain
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/x-component
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/javascript
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/json
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/xhtml+xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/rss+xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/atom+xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/vnd.ms-fontobject
FilterProvider COMPRESS DEFLATE resp=Content-Type $image/svg+xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $image/x-icon
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/x-font-ttf
FilterProvider COMPRESS DEFLATE resp=Content-Type $font/opentype
FilterChain COMPRESS
FilterProtocol COMPRESS DEFLATE change=yes;byteranges=no
</IfModule>
<IfModule !mod_filter.c>
# Legacy versions of Apache
AddOutputFilterByType DEFLATE text/html text/plain text/css application/json
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE text/xml application/xml text/x-component
AddOutputFilterByType DEFLATE application/xhtml+xml application/rss+xml application/atom+xml
AddOutputFilterByType DEFLATE image/x-icon image/svg+xml application/vnd.ms-fontobject application/x-font-ttf font/opentype
</IfModule>
</IfModule>
This one Doesnt seem to do anything...
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/x-javascript
I followed the tutorial found here
(http://mrrena.blogspot.com/2009/01/how-to-compress-php-and-other-text.html)
but this essentially completely broke the appearance of my site.
Tried this in my Functions.php, and it seemed to compress my html, but leaves some js and css uncompressed
if(extension_loaded("zlib") && (ini_get("output_handler") != "ob_gzhandler"))
add_action('wp', create_function('', '#ob_end_clean();#ini_set("zlib.output_compression", 1);'));
So, after a while I figured out how to compress html, css and js files having a 1&1 Webhosting package. Deflate is not supported!
For the dynamic content you add php.ini to your root directory of your website. Content of php.ini:
zlib.output_compression =1
zlib.output_compression_level =9
Of course you can also choose another compression level, 9 is the highest (and causing the highest server load). That will compress your the dynamically generated html file.
To compress static files (css, js and images...) you need to modify the .htaccess file. For that append
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteOptions Inherit
ReWriteCond %{HTTP:accept-encoding} (gzip.*)
ReWriteCond %{REQUEST_FILENAME} !.+\.gz$
RewriteCond %{REQUEST_FILENAME}.gz -f
RewriteRule (.+) $1.gz [QSA,L]
</IfModule>
to your .htaccess file (you find that file in the root directory of your website - else create it).
But the compression is not done automatically. So you have to compress the files on your own! Use e.g. 7-zip and compress the js and css files with .gz -> the result should be e.g. stylesheet.css.gz.
Then upload the file to the same directory as the file you just compressed.
Now it should work!
PS: compression is not always useful especially when the file is very small. So check the differences before and after compression.
It looks to me like you have exhausted your option. Looking at the above it seems like the host indeed doesn't have mod_deflate or mod_gzip. So I guess you are just out of luck.
The PHP solution is indeed only for the HTML. So just stick with that one. HTML is also the best place to add compression, as, most of the time, the CSS and JS are only downloaded on the first page.
You could redirect the request to CSS and JS though a PHP script, and use the PHP to compress. But I would not go there, as you would also have to implement 304 Not modified and set the appropriate expires headers.
Enable gzip compression
The gzip compression can be activated in php.ini with the following code:
zlib.output_compression = On
zlib.output_compression_level = 9
allow_url_fopen = On
I know this question is a bit old now, but I've found a solution that works for me.
Add a file called "php.ini" to the root folder containing the following;
zlib.output_compression = On
zlib.output_compression_level = 9
Then (and this is the bit you might not expect) add the following to your .htaccess file;
AddType x-mapp-php6 .html .htm .php
Yes, that's right. I've put php6 in that. Apparently that will run the latest stable version of PHP (currently 5.4) which will allow gzip compression. This will also run .html and .htm files through the PHP parser, which means that they can be compressed (files not run through the PHP parser will not be compressed). Feel free to add any other extensions that you want to be run through PHP (.xml for example).
By the way, if you do run .xml files through PHP, remember to set the header declaring it as an xml file, otherwise it won't work properly.
Hope this helps!
Works for me,
First you have to copy the php.ini in all directory.
(1and1 provided a script to facilitate this manipulation in their faq)
with this content :
zlib.output_compression =1
zlib.output_compression_level =9
Then add this in the htaccess :
<IfModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_item_exclude file \.(gz|zip|xsl)$
mod_gzip_item_include mime ^text/html$
mod_gzip_item_include mime ^text/plain$
mod_gzip_item_include mime ^image/x-icon$
mod_gzip_item_include mime ^httpd/unix-directory$
mod_gzip_item_include mime ^text/javascript$
mod_gzip_item_include mime ^application/javascript$
mod_gzip_item_include mime ^application/x-javascript$
mod_gzip_item_include mime ^text/x-js$
mod_gzip_item_include mime ^text/ecmascript$
mod_gzip_item_include mime ^application/ecmascript$
mod_gzip_item_include mime ^text/vbscript$
mod_gzip_item_include mime ^text/fluffscript$
mod_gzip_item_include mime ^text/css$
</IfModule>
You can enable compression by adding this code into your .htaccess file :
<IfModule mod_rewrite.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml image/svg+xml image/x-icon text/css application/x-javascript application/javascript application/x-httpd-php application/x-httpd-fastphp application/x-httpd-eruby
</IfModule>
im trying to include css.gz from external source, but still not works on all browsers
<link rel="stylesheet" type="text/css" media="all" href="http://www.website.com/style.css.gz" />
i dont know what is the problem
(my web server: nginx, and test server: apache)
thanks
If you have access to the .htaccess file you can use this script to gzip css only to browsers that support it:
# This uses mod_deflate, which is pretty standard on Apache 2. Loading
# mod_deflate looks like this:
#
# LoadModule deflate_module modules/mod_deflate.so
#
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css application/x-javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \\bMSIE !no-gzip !gzip-only-text/html
See the original post: How can I make my .htaccess file allow Safari & other browsers to open GZIP?