How to enable Gzip compression

Source: https://varvy.com/pagespeed/enable-compression.html
https://knackforge.com/blog/karalmax/how-enable-gzip-compression-apache

The code below should be added to your .htaccess file...
<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>
The instructions and code above will work on Apache. If they are not working there is another way that may work for you. If the above code did not seem to work, remove it from your .htaccess file and try this one instead...
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
There is no mod_gzip for Apache 2.2x, as it is an Apache 1.3x module. Apache 2.2x has a only mod_deflate. GZip is the same DEFLATE plus a checksum and header/footer. As you can see here, Deflate is faster.


mod_deflate module is shipped with Apache, but in order to use it, you should enable one in your httpd.conf file (it is initially commented out):
LoadModule deflate_module modules/mod_deflate.so
After that just add following to the httpd.conf:
SetOutputFilter DEFLATE 
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript
For more tuning refer, as was mentioned: http://httpd.apache.org/docs/2.2/mod/mod_deflate.html

HOW TO ENABLE GZIP COMPRESSION IN APACHE

The mod_deflate module provides the DEFLATE output filter that allows the output from your server to be compressed before being sent to the client over the network. mod_deflate is the replacement of mod_gzip which was used with an older version of Apache.

ENABLE GZIP MODULE IN APACHE

       By default, a mod_deflate module is enabled in Apache. To make sure that it is enabled, check following line in Apache configuration file.
LoadModule deflate_module modules/mod_deflate.so

CONFIGURE GZIP COMPRESSION

      Now edit your apache configuration and add the extensions you want to compress.
nano /etc/httpd/conf/httpd.conf
Add the following lines at end of the file
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
Restart Apache service,
## CentOS ##
sudo service httpd restart
## Ubuntu ##
sudo /etc/init.d/apache2 restart
Add the following configuration in Apache Virtual Host to enable gzip compression for your website. You can also add this code in website's .htaccess file in the site root.
<Directory /var/www/html/>
   <IfModule mod_mime.c>
 AddType application/x-javascript .js
 AddType text/css .css
   </IfModule>
   <IfModule mod_deflate.c>
 AddOutputFilterByType DEFLATE text/css application/x-javascript text/x-component text/html text/plain text/xml application/javascript
 <IfModule mod_setenvif.c>
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4.0[678] no-gzip
  BrowserMatch bMSIE !no-gzip !gzip-only-text/html
 </IfModule>
    </IfModule>
    Header append Vary User-Agent env=!dont-vary
</Directory>
TESTING COMPRESSION
We have enabled gzip compression, let’s use one of below online tools to verify gzip is working correctly.

Không có nhận xét nào:

StaticImage

  import React , { useEffect , useRef } from "react" import { StaticImage } from "gatsby-plugin-image" impor...