Mitrahsoft
  • SERVICES
    • OUR SERVICES
      • SOFTWARE DEVELOPMENT
      • MOBILE DEVELOPMENT
      • BLOCKCHAIN DEVELOPMENT
      • SOFTWARE TESTING
      • CLOUD & DEVOPS SERVICES
      • PRODUCT DEVELOPMENT
      • OFFSHORE DEVELOPMENT
      • SOCIAL MEDIA MARKETING
      TECHNOLOGIES
      • COLDFUSION DEVELOPMENT
      • REACTJS DEVELOPMENT
      • VUEJS DEVELOPMENT
      • ANGULAR DEVELOPMENT
      • NODEJS DEVELOPMENT
      • PYTHON DEVELOPMENT
      • GOLANG DEVELOPMENT
      • GOLANG CORPORATE TRAINING
      COLDFUSION EXPERTISE
      • MURACMS EXPERTISE
      • COLDFUSION APP MIGRATION
      • COLDFUSION HOSTING & SUPPORT
      • CF LEGACY APP MAINTENANCE
      • COLDFUSION REST API
      • ECOMMERCE / SHOPPING CART SOLUTIONS
      • PRESIDECMS EXPERTISE
      MOBILE DEVELOPMENT
      • REACT NATIVE DEVELOPMENT
      • FLUTTER DEVELOPMENT
      • IONIC DEVELOPMENT
      • PHONEGAP DEVELOPMENT
  • ABOUT US
    • ABOUT MITRAHSOFT
    • OUR CLIENTS
    • TESTIMONIALS
    • PORTFOLIO
    • CAREERS
  • CONTACT US
  • BLOG
Adobe Solution PartnerLucee Solution Partner
Adobe Solution PartnerLucee Solution Partner
Adobe Solution PartnerLucee Solution Partner
  • OUR SERVICESSOFTWARE DEVELOPMENTMOBILE DEVELOPMENTBLOCKCHAIN DEVELOPMENTSOFTWARE TESTINGCLOUD & DEVOPS SERVICESPRODUCT DEVELOPMENTOFFSHORE DEVELOPMENTSOCIAL MEDIA MARKETING
    TECHNOLOGIESCOLDFUSION DEVELOPMENTREACTJS DEVELOPMENTVUEJS DEVELOPMENTANGULAR DEVELOPMENTNODEJS DEVELOPMENTPYTHON DEVELOPMENTGOLANG DEVELOPMENTGOLANG CORPORATE TRAINING
    COLDFUSION EXPERTISEMURACMS EXPERTISECOLDFUSION APP MIGRATIONCOLDFUSION HOSTING & SUPPORTCF LEGACY APP MAINTENANCECOLDFUSION REST API ECOMMERCE / SHOPPING CART SOLUTIONSPRESIDECMS EXPERTISE
    MOBILE DEVELOPMENTREACT NATIVE DEVELOPMENTFLUTTER DEVELOPMENTIONIC DEVELOPMENTPHONEGAP DEVELOPMENT
  • ABOUT MITRAHSOFTOUR CLIENTSTESTIMONIALSPORTFOLIOCAREERS
  • CONTACT US
  • BLOG

Apache HTTP/2 And Gzip Compression

HomeBlogApache HTTP/2 And Gzip Compression
ColdFusionApache

Apache HTTP/2 And Gzip Compression

M
Post by MitrahsoftPublished: Jan 10, 2019

Now a days everyone want to make sure that, their websites are loading in fraction of seconds including all its assets ( css, js, images etc ). Eventually we call it as performance. A site's performance is not only depending upon the server side or javascript code. Possibly your web server can do something about the performance. If We are trying to load a large size image in a page & client's browser may take more time to render the page based on the bandwidth.

Without doing any code changes, we can partially achieve that by simply upgrading our Apache web server's HTTP version to HTTP 2.0 and enabling Gzip compression. Here we will talk about, what are the benefits of using HTTP 2.0 & Gzip. As well as, we will see, how to configure those in Apache web server.
Apache HTTP 2 and Gzip Compression

What is HTTP/2.0 ?

HTTP/2 is the evolution of the world's most successful application layer protocol, HTTP. It focuses on making more efficient use of network resources. It does not change the fundamentals of HTTP. it dramatically improves website performance with no downside.

Features of HTTP/2:

  • Reduces latency for fast loading the page.
  • Multiplexing of request and response.
  • Header compression.
  • Prioritizing the requests.

Important Note:

It can be used over Secure (HTTPS) with TLS and non-secure (HTTP) protocols, but all the major browsers like Mozilla, Chrome, IE, Safari, Edge had stated that they will support HTTP/2 only with Secure Version of HTTP means HTTPS with TLS). Thus HTTPS is mandatory for using HTTPS over these browsers.

Basic Configuration:
Apache Basic Configuration

  1. The first thing, as with every Apache module, is that you need to load it: LoadModule http2_module modules/mod_http2.so This module available from apache version 2.4, By default the module not enabled, we should enable that.

For windows users:

To enable the HTTP 2.0 module goto apache\conf\httpd.conf file, Find LoadModule http2_module modules/mod_http2.so. If the line prefix with # symbol then remove the # and then save.

  1. The second directive you need to add to your server configuration is Protocols h2 http/1.1 (h2 is HTTP/2 over TLS).
  2. This allows h2, the secure variant, to be the preferred protocol on your server connections. When you want to enable all HTTP/2 variants, you simply write: Protocols h2 h2c http/1.1 (h2c is HTTP/2 over TCP)+
  3. Depending on where you put this directive, it affects all connections or just the ones to a certain virtual host. You can nest it, as in:
apache
Protocols http/1.1 
<VirtualHost> 
    ServerName test.example.org 
    Protocols h2 http/1.1
</VirtualHost>

The order of protocols mentioned is also relevant. By default, the first one is the most preferred protocol. When a client offers multiple choices, the one most to the left is selected. In Protocols http/1.1 h2 , the most preferred protocol is HTTP/1 and it will always be selected unless a client only supports h2. Since we want to talk HTTP/2 to clients that support it, the better order is Protocols h2 h2c http/1.1

There is one more thing in ordering of your options: the client has its own preferences, too. If you want, you can configure your server to select the protocol most preferred by the client: ProtocolsHonorOrder Off

  1. After finished the above configurations restart the apache service.

    Gzip compression

    What is Gzip compression ?
    • Gzip is a method of compressing files (making them smaller) for faster network transfers.It is also a file format.
    • When a user hits your website a call is made to your server to deliver the requested files.
    • The bigger these files are the longer it's going to take for them to get to your browser and appear on the screen.
    • Gzip compresses your web pages and style sheets before sending them over to the browser. This drastically reduces transfer time since the files are much smaller.
    • 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.
    How does it work ?
    • Gzip is actually a fairly simple idea that is extremely powerful when put to good use. Gzip locates similar strings within a text file and replaces those strings temporarily to make the overall file size smaller.
    • The reason Gzip works so well in a web environment is because CSS files and HTML files use a lot of repeated text and have loads of whitespace. Since Gzip compresses common strings, this can reduce the size of pages and style sheets by up to 70%!
    • When a browser visits a web server it checks to see if the server has Gzip enabled and requests the web page. If it's enabled it receives the Gzip file which is significantly smaller and if it isn't, it still receives the page, only the uncompressed version which is much larger.

    Why is it important ?

    The main reason it is important is because it reduces the time it takes for a website to transfer the page files and style sheets which ultimately reduces the load time of your website.

    How compressed files work on the web ?

    When a request is made by a browser for a page from your site your webserver returns the smaller compressed file if the browser indicates that it understands the compression. All modern browsers understand and accept compressed files.

    How to configure Gzip compression:
    1. Enable the mod_deflate & mod_filter( #LoadModule deflate_module modules/mod_deflate.so and LoadModule filter_module modules/mod_filter.so) module.
    2. Add the following lines at end of the httpd.conf file.

    apache
    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
    1. 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.
apache
<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> (only needed for really old browsers)
            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>
  1. Restart the apache service.
  2. We have enabled gzip compression, let's use one of below online tools to verify gzip is working correctly.
    • Zip compression
    • HTTP Compression test

      Optimizing Website Speed Using Apche

Tags

ADYENAMAZON-SESANDROIDAPACHEAPACHE-JMETERAWSBARCODE-SCANNERCOLDBOXCOLDFUSIONCOLDFUSION-API-INTEGRATIONCOLDFUSIONBUILDERECHARTSEVENT-GATEWAYFFMPEGFW1JQUERYJSOUPLUCEEMURACMSMURACMS-THEMENODEJSONESIGNALOSSPAYFLOW-PROPAYMENT-GATEWAYPAYPALPRESIDECMSPUPPETEERRAILORAZUNAREACTJSREACTNATIVERESTSASS-COMPILATIONSEMANTIC-UISUBLIMETEXTTINYMCETWILIOYUI-LIBRARY

Archives

JAN 20DEC 19AUG 19JUL 19JUN 19MAY 19APR 19MAR 19FEB 19JAN 19DEC 18NOV 18OCT 18MAR 16NOV 15SEP 15MAY 15MAY 14OCT 13JUN 13MAY 13APR 13MAR 13FEB 13JAN 13

Follow us

Mitrahsoft
United StatesUnited States

Hurst, Texas, United States

+1 (817) 606-8684usa-sales@mitrahsoft.com

IndiaIndia

Head Office

126G2/5, Thiru malai nagaram,
Kovilpatti - 628 501

Madurai

1/B, 2nd & 3rd floor, GV Complex,

Bye Pass Road, SS Colony,

Madurai - 625 016

Coimbatore

2nd Floor, Sri Narmadha Towers,

Murugan Nagar Rd, Thoppampatti Pirivu,

 K. Vadamadurai, Coimbatore - 641 017

+91 9092480924

business@mitrahsoft.com

ColdFusion
  • eCommerce / Shopping Cart Solutions
  • Payment Gateway Integrations
  • Shipping API Integrations
  • ColdFusion Development Services
  • REST API Development
  • MuraCMS Plugin Creation & Personalization
Technology Services
  • ReactJS Development
  • VueJS Development
  • AngularJS Development
  • NodeJS API Development
  • Python Development
  • Golang Development
  • React Native Development
  • D3.JS data Visualization
Other Services
  • Software Development
  • Mobile Development
  • Blockchain Development
  • Cloud & Devops Services

Connect with MitrahSoft

Please fill out this field
Please fill out this field
Please fill out this field
Please fill out this field
Please fill out this field
Please fill out this field

© 2026 All Rights Reserved. MitrahSoft Solutions Pvt Ltd

Home|About Us|Careers