How to make gzip work on 1and1 shared host WordPress site

前端 未结 6 2059
温柔的废话
温柔的废话 2021-01-05 02:15

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

6条回答
  •  醉话见心
    2021-01-05 03:10

    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

    
    RewriteEngine on
    RewriteBase /
    RewriteOptions Inherit
    ReWriteCond %{HTTP:accept-encoding} (gzip.*) 
    ReWriteCond %{REQUEST_FILENAME} !.+\.gz$ 
    RewriteCond %{REQUEST_FILENAME}.gz -f 
    RewriteRule (.+) $1.gz [QSA,L] 
    
    

    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.

提交回复
热议问题