How to get gzip to work with a common WordPress site 1 and 1

YSlow tells me that my css should be compressed, but after a few hours of messing around, I canโ€™t get gzip for life on my site for my whole life. At the moment, I'm not even sure that an increase in productivity (will it be?) Will be worth the effort.

I am launching a WordPress site on 1 and 1 public hosting account.

Honestly, I really don't know what I'm doing with this stuff, and I seem to be unable to get a suitable setting. I read in several places that with 1 & 1, "Apache modules mod_deflate and mod_gzip are not installed," so I assume this is part of the problem.

I tried the following code:

This does nothing:

<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 the html5 template) does nothing 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 seems to do nothing ...

 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 it essentially completely violated the look of my site.


Tried this in my Function.php and 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);')); 
+8
gzip wordpress .htaccess
source share
6 answers

So, after a while I figured out how to compress html, css and js files having a 1 & 1 web hosting package. Deflate is not supported!

For dynamic content, you add php.ini to your websiteโ€™s root directory. The contents of php.ini:

 zlib.output_compression =1 zlib.output_compression_level =9 

Of course, you can also choose a different compression level, 9 - the highest (and causing the highest load on the server). This compresses your dynamically generated html file.

To compress static files (css, js and images ...), you need to modify the .htaccess file. To do this, add

 <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> 

into your .htaccess file (you will find this file in the root directory of your site, and then create it). But compression is not performed automatically. Therefore, you need to compress the files yourself! Use for example. 7-zip and compress js and css files with .gz -> the result should be, for example, stylesheet.css.gz. Then upload the file to the same directory as the compressed file.

Now it should work!

PS: compression is not always useful, especially when the file is very small. Therefore, check the differences before and after compression.

+13
source share

It seems to me that you have exhausted your option. Looking at the above, it seems that the host really does not have mod_deflate or mod_gzip. So I think you're just out of luck.

The PHP solution is valid only for HTML. So just stick to it. HTML is also the best place to add compression, since most of the time, CSS and JS only load on the first page.

You can redirect the request to CSS and JS, although a PHP script, and use PHP to compress. But I would not go there, since you would also need to implement 304 Not modified and set the appropriate expiration headers.

+7
source share

Enable gzip compression
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 
+6
source share

I know this question is a bit outdated, but I found a solution that works for me.

Add the php.ini file to the root folder containing the following:

 zlib.output_compression = On zlib.output_compression_level = 9 

Then (and this is a bit you do not expect) add the following to your .htaccess file;

 AddType x-mapp-php6 .html .htm .php 

Yes, that's right. I put php6 . Obviously, the latest stable version of PHP (currently 5.4) will work, which will allow gzip compression. It will also run .html and .htm files through the PHP parser, which means they can be compressed (files that do not run through the PHP parser will not be compressed). Feel free to add any other extensions you want to run through PHP (like .xml ).

By the way, if you run .xml through PHP, do not forget to specify a header declaring it as an xml file, otherwise it will not work properly.

Hope this helps!

+2
source share

Works for me

First you need to copy php.ini to the entire directory. (1 and 1 provided a script to facilitate this manipulation in their situation) with this content:

 zlib.output_compression =1 zlib.output_compression_level =9 

Then add this to 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> 
+1
source share

You can enable compression by adding this code to 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> 
0
source share

All Articles