Speed up your website with the perfect .htaccess file

I was doing some research about the guidelines that Google and Yahoo offer for speeding up websites, and kind of found that the quickest thing that you could do is add a .htacces file to your document root of your project. With this quick trick you can speed up your website dramatically. Of course, I’m assuming the use of Apache web server which uses this file. This should give you a big boost in performance of your website and probably give you a score of almost 90 in Google Page Speed test.

# disable the server signature
ServerSignature Off

# Enable compression
<IfModule mod_deflate.c>
  <FilesMatch "\.(js|css|php|eot|ttf|otf|svg)$">
    SetOutputFilter DEFLATE
  </FilesMatch>
</IfModule>

# Control ETags which is thought that bring better performance
<IfModule mod_headers.c>
    Header unset ETag
</IfModule>
FileETag None

<IfModule mod_headers.c>
  <FilesMatch "\.(js|css|xml|gz)$">
    Header append Vary Accept-Encoding
  </FilesMatch>
</IfModule>

<IfModule mod_expires.c>

    # Enable expirations
    ExpiresActive On

    # Default directive
    ExpiresDefault "access plus 1 month"

    # My favicon
    ExpiresByType image/x-icon "access plus 1 year”

    # Images
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType image/jpg "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"

    # CSS
    ExpiresByType text/css "access 1 month”

    # Javascript
    ExpiresByType application/javascript "access plus 1 year"

</IfModule>

Posted

in

, ,

by

Tags: