Boost up Website performance with .htacess Rules
Most of the time user having problem of slowness of website or not optimize server configuration , so performance analyzing websites showing some recommendation like disable etag , add expire header and compression of text etc.. Here i am explaining how we can enable or disable these modules through .htaccess
Unset or Disable ETag
ETags label is used in server to figure out the component of browser’s is matched with the server where it is originated . Lots of website performance tools like YSlow or Yahoo Performance rules , suggest to disable Etags will make page load fast and reduce resource utilization like bandwidth. If you are running multiple server behind load-balanced server with apache webserver then we should disable Etag generation because etag mechanism use inodes which will be different on different on multiple server for individual website.
Follow below steps to disable Etags.
(1) Go to the document root of website and Edit the .htacess file through vim editior.
# vim .htacess
(2) Add below lines of code in .htaccess file.
Header unset ETag FileETag None
(3) Save and Exit from vim editor
Now test the performance .
and If you do not want to compress all files , you can mention specific file extension like below in .htaccess
<FilesMatch ".(css| js||html|xml|htm|php)$"> SetOutputFilter DEFLATE </FilesMatch>
Add Expires Headers Time
The Expires header is utilized by the proxies or caches client to figure out if or not it even needs to make a request to the server by any means. The closer you are to the Expires date, the more probable it is the client will make a HTTP ask for that record from the server.
There are lot of method to add expires header time thorugh .htaccess. Here i am adding basis rules.You can add Expires time thorugh below method.
Header set Expires "Fri, 23 Oct 2025 00:00:00 EST"
If you want to add expires headers for some file types only, use the following code:
<FilesMatch ".(js|ico|jpg|jpeg|png|gif|swf|css)$"> Header set Expires "Fri,23 Oct 2025 00:00:00 EST" </FilesMatch>
Thanks for reading post , if you have any query you can ask in comments