Improving web site performance with Apache .htaccess
Speed optimizations can be easily done with simple .htaccess rules. These rules can make any website faster by compressing content and enabling browser cache.
.htaccess is a special configuration file which you should be able to dig up in the root of your server directory. With a .htaccess file you can create redirects, rewrite URLs on your website, create password protected directories and other technical things, but you can also use them to improve your site’s page loading speed by taking advantage of some Apache server features.
Compression reduces response times by reducing the size of the HTTP response. It’s worthwhile to gzip your HTML documents, scripts and stylesheets. Gzip compression helps to reduce the amount of data your server needs to send to your users, which in turn speeds up the load time of your site.
You can use the Apache mod_deflate module to compress output from your web site that is sent to client browsers.
When a new visitor enters your website all the files like scripts, CSS styles and images are downloaded – there is no way to avoid it and it naturally produces several requests to your server. But what if this visitor comes back to your website later? We can tell the user’s browser to store these files in its cache; then, when the user returns to your site it will reload the files from the cache rather than downloading them all again.
In order to add browser caching to your website, you will need to set the date for when the cache expires.
Browser cache control is directly related to the header expires date and according to the Apache, documentation provides directives to control and modify HTTP request and response headers. Headers can be merged, replaced or removed. You can use this feature by including this code in your htaccess