- Part One Chapter 07 – Enable File Compression
Part One Chapter 07
When a user visits one of your mobile web pages, http requests for your page are sent to your web server. Your web server will return http responses (i.e. the data of your page) to the requesting web browser. Each response takes up certain amount of file size.
When the file size of the http responses (i.e. data file size of your web page) is reduced, then the transfer time decreases as fewer data packets must be transferred from your web server and the user's web browser. In this way, the user can load your mobile web page through the web browser faster.
Reduce Data File Size
To reduce data file size, you should enable file compression.
- Gzip compression is a typical file compression method and can compress your HTML and CSS files into smaller sizes.
- The compressed file size may become significantly smaller. In some cases, the compressed file size may be 50% smaller than the original size.
How Compression Works
Assume your HTML and CSS files have been compressed. For file compression to work between web browsers and your web server:
- You will have to enable Gzip compression through your web server configurations. The configurations are web server specific, assuming your mobile website may be using Apache or Nginx as web server.
When the web browser (that supports Gzip compression) requests a page from your mobile website, your web server will return the compressed file.
Enable Gzip Compression for Apache
Apache has two options for enabling Gzip compression:
- mod_deflate: It is standard and easier to set up.
- mod_gzip: It is more powerful which allows pre-compression of content, but it is more complicated to set up.
To enable Gzip compression on Apache, you should add the code below to the .htaccess file.
Enable Gzip Compression for Nginx
To enable Gzip compression on Nginx, add the code below to the config file.
Thank you for reading! If you love my book, you're welcome to donate through Paypal.
Content on Gordon Choi's Mobile Website Book is licensed under the CC Attribution-Noncommercial 4.0 International license.