Speed up your page load time with Mod Deflate and Cache-Control

Want to increase the speed of your website easily, in a few simple steps? Activation of mod_deflate (mod_gzip) and mod_expires is probably the first thing to do before optimizing your scripts.

Before beginning, here is a little more explanation on these two systems:
 

 Gzip et Deflate (mod_gzip and mod_deflate)

Deflate is gzip, also called mod_deflate and mod_gzip are Apache modules that allow compressing the resource requested by the client before delivering it, making the requested source much smaller and thereby the transmission time to the client of this resource will be shortened because the resource will be up to 4 times smaller. Please note that gzip is not good for the images, it is recommended to use it for text files, such as HTML, JavaScripts, CSS and font file.
 

 Cache-control (mod_expires)

The cache-control also called mod_expires is an Apache module for delivering a resource only if it is not in the cache of the visitor’s browser and, if so, the client will not have to re-download this resource, the module will load the resource directly from the browser cache, so no request will have to be done on the server.
 

 Enabling Gzip et Cache-control

By default, these modules are installed on all our servers. To enable these options, very simple, add the code below at the beginning of the .htaccess file located in the root of your website (usually in the public_html). If the .htaccess file does not exist, you can create it. If there are already values present in the .htaccess file, you must leave what is present and add your code at the absolute beginning of the file. You can do this via FTP or directly with the file manager that is in your cPanel account:

#Activation du Mod Deflate
<IfModule mod_deflate.c>
  # Compresse les fichiers HTML, CSS, JavaScript, Text, XML et les fonts 
  AddOutputFilterByType DEFLATE application/javascript
  AddOutputFilterByType DEFLATE application/rss+xml
  AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
  AddOutputFilterByType DEFLATE application/x-font
  AddOutputFilterByType DEFLATE application/x-font-opentype
  AddOutputFilterByType DEFLATE application/x-font-otf
  AddOutputFilterByType DEFLATE application/x-font-truetype
  AddOutputFilterByType DEFLATE application/x-font-ttf
  AddOutputFilterByType DEFLATE application/x-javascript
  AddOutputFilterByType DEFLATE application/xhtml+xml
  AddOutputFilterByType DEFLATE application/xml
  AddOutputFilterByType DEFLATE font/opentype
  AddOutputFilterByType DEFLATE font/otf
  AddOutputFilterByType DEFLATE font/ttf
  AddOutputFilterByType DEFLATE image/svg+xml
  AddOutputFilterByType DEFLATE image/x-icon
  AddOutputFilterByType DEFLATE text/css
  AddOutputFilterByType DEFLATE text/html
  AddOutputFilterByType DEFLATE text/javascript
  AddOutputFilterByType DEFLATE text/plain
  AddOutputFilterByType DEFLATE text/xml

  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4\.0[678] no-gzip
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
  Header append Vary User-Agent
</IfModule>
#Activation of mod Expires
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresDefault "access plus 7 days"
</IfModule>

Now you just activated Gzip and Cache-control on your site, these entries should be good for 90% of CMS and web sites, you can adjust it as needed. You can use the Dareboost tool to validate if it is active on your site. Please note that these values only affect resources hosted on your server, not the resources hosted on other servers, such as fonts hosted at Google. If the result is negative make sure that you have entered it in the right .htaccess file.


facebooktwitterlinkedin

Subscribe to our newsletter to take advantage of exclusive offers!



Leave a Reply

Your email address will not be published. Required fields are marked *