{"id":603,"date":"2019-09-18T23:23:44","date_gmt":"2019-09-18T23:23:44","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/2019\/09\/18\/enable-gzip-compression-for-magento\/"},"modified":"2025-05-22T15:58:31","modified_gmt":"2025-05-22T10:28:31","slug":"enable-gzip-compression-for-magento","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/enable-gzip-compression-for-magento\/","title":{"rendered":"How To Enable GZIP Compression for Magento"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">GZIP compression is a standard method to compress files for faster webpage loading.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When a visitor visits the site, the server is called to deliver the requested files. If these files are larger in the size, it causes a higher load time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Bigger the file, longer it takes to display the result to the visitor.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With GZIP compression, the files are compressed before sending them to the browser, resulting in reducing the load time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">According to <a href=\"https:\/\/gtmetrix.com\/enable-gzip-compression.html\" target=\"_blank\" rel=\"noreferrer noopener\">GTmetrix<\/a>, GZIP compression reduces the size of pages and style sheets by up to 70%! And thus, optimizing your webpages by enabling GZIP compression should be your priority if you want to outrank the competitors and offer a smooth user experience.&nbsp;And for Magento 2 and Magento stores, it is not an option to ignore performance optimization.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Ecommerce platform must be optimized for quick shopping owing to the cutthroat competition. And as a store owner, you can just start with the below method to <strong>enable GZIP compression for Magento<\/strong><em><strong> <\/strong><\/em>stores!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Method To Enable GZIP Compression for Magento:<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Make sure <code>mod_deflate<\/code>&nbsp;is on in Apache. You can check by creating an <code>info.php<\/code>&nbsp;file and calling <code>phpinfo();<\/code>. It will output server PHP \/ Apache specs in the browser. Don\u2019t forget to remove it when you\u2019re done!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Then add the following to your <code>htaccess<\/code>&nbsp;file<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;IfModule mod_php5.c>\n\n## enable resulting html compression\n\nphp_flag zlib.output_compression on\n\n&lt;\/IfModule>\n\n&lt;IfModule mod_php7.c>\n   ## enable resulting html compression\n  php_flag zlib.output_compression on\n&lt;\/IfModule>\n\n&lt;IfModule mod_deflate.c>\n\n## Force compression for mangled `Accept-Encoding` request headers\n\n&lt;IfModule mod_setenvif.c>\n\n&lt;IfModule mod_headers.c>\n\nSetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\\s*,?\\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding\n\nRequestHeader append Accept-Encoding \"gzip,deflate\" env=HAVE_Accept-Encoding\n\n&lt;\/IfModule>\n\n&lt;\/IfModule>\n\n## Compress all output labeled with one of the following media types.\n\n&lt;IfModule mod_filter.c>\n\nAddOutputFilterByType DEFLATE \"application\/atom+xml\" \\\n\n\"application\/javascript\" \\\n\n\"application\/json\" \\\n\n\"application\/ld+json\" \\\n\n\"application\/manifest+json\" \\\n\n\"application\/rdf+xml\" \\\n\n\"application\/rss+xml\" \\\n\n\"application\/schema+json\" \\\n\n\"application\/vnd.geo+json\" \\\n\n\"application\/vnd.ms-fontobject\" \\\n\n\"application\/x-font-ttf\" \\\n\n\"application\/x-javascript\" \\\n\n\"application\/x-web-app-manifest+json\" \\\n\n\"application\/xhtml+xml\" \\\n\n\"application\/xml\" \\\n\n\"font\/eot\" \\\n\n\"font\/opentype\" \\\n\n\"image\/bmp\" \\\n\n\"image\/svg+xml\" \\\n\n\"image\/vnd.microsoft.icon\" \\\n\n\"image\/x-icon\" \\\n\n\"text\/cache-manifest\" \\\n\n\"text\/css\" \\\n\n\"text\/html\" \\\n\n\"text\/javascript\" \\\n\n\"text\/plain\" \\\n\n\"text\/vcard\" \\\n\n\"text\/vnd.rim.location.xloc\" \\\n\n\"text\/vtt\" \\\n\n\"text\/x-component\" \\\n\n\"text\/x-cross-domain-policy\" \\\n\n\"text\/xml\"\n\n&lt;\/IfModule>\n\n## Map the following filename extensions to the specified\n\n## encoding type in order to make Apache serve the file types\n\n## with the appropriate `Content-Encoding` response header\n\n## (do note that this will NOT make Apache compress them!).\n\n&lt;IfModule mod_mime.c>\n\nAddEncoding gzip svgz\n\n&lt;\/IfModule>\n\n&lt;\/IfModule><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you are looking for other ways to optimize the Magento 2 store performance, follow the checklist at <a href=\"https:\/\/meetanshi.com\/blog\/speed-up-magento-2\/\" target=\"_blank\" rel=\"noreferrer noopener\">How do I Speed Up Magento 2<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Boost the Magento 2 store speed and enjoy the top rank because site speed is surely one of the important factors to decide the same for the search engines!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You may share this post on social media to help the community optimize their Magento 2 stores!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thanks.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>GZIP compression is a standard method to compress files for faster webpage loading. When a visitor visits the site, the server is called to deliver&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-603","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/603","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=603"}],"version-history":[{"count":3,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/603\/revisions"}],"predecessor-version":[{"id":15265,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/603\/revisions\/15265"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=603"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=603"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=603"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}