
Website speed is crucial for user experience, One of the most effective ways to improve loading times is by enabling Gzip compression. Compressing content before sending it over the Internet reduces the size of transmitted data and shortens the time taken to load the content. Gzip compression makes web applications faster by shrinking web pages, scripts, and stylesheets to smaller sizes before serving them to a visitor on your server. This results in faster page loads, lower bandwidth usage, and happier visitors.
When a user calls your website through a web browser, the server responds by delivering the requested file. But since bigger files take longer to load, Gzip compression makes the requested files smaller for the browser to decompress before serving them to the user.
In this article, you will enable and configure Gzip compression on Apache and Nginx running on either a Debian or RHEL based server distribution like Ubuntu, CentOS, respectively.
Apache supports Gzip compression through the mod_deflate module referenced by DEFLATE. By default, the module is turned on, but in any case, you should check whether it’s available with the following commands.
On Debian or Ubuntu
On CentOS
Your output should be similar to:
Else, enable DEFLATE
Open your Apache virtual host file and enable gzip compression entries line by line. For example, to compress HTML, text, XML, CSS, and Javascript content types, add the following line to your virtual host or .htaccess file.
text/html will compress HTML files, text/plain compresses all text files, text/xml will compress xml files and application/javascript works on Javascript files.
You can also enable compression on specific file extensions by using the SetOutputFilter directive.
To enable server-wide compression for all hosted web pages, add the following code to your apache2.conf or httpd.conf.
Gzip is enabled on Nginx by default, but in any case, you should open the main configuration file nginx.conf and confirm that the gzip section entries are uncommented.
To turn on Gzip compression, simply add on to the gzip directive in the main Nginx configuration file.
Add file types to compress.
Set the minimum length of a response to compress, the default is 20 bytes.
Save and close the file.
Your Nginx Configuration file should now look similar to the one below.
0 Comments
Be the first to comment and share your perspective with the community.