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.
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
You can use the Apache mod_deflate module to compress output from your web site that is sent to client browsers.
# Enable Compression
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/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/plain
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.
# Leverage Browser Caching
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
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
Header set Connection keep-alive
Header set Cache-Control "max-age=2678400, public"
Header set Cache-Control "max-age=7200, private, must-revalidate"
Header set Cache-Control "max-age=86400, public"
Header set Cache-Control "max-age=2678400, private"
How do I enable .htaccess in AbanteCart?
After installing AbanteCart a .htaccess file is already created, but it’s called .htaccess.txt and looks like a regular text file. The reason for this? Compatibility. There’s no guarantee that every server that AbanteCart is installed on will support .htaccess features. Don’t worry though; most modern servers that are built to support AbanteCart will also support .htaccess
You just need to rename the htaccess.txt file to .htaccess (remember about the dot that comes before “htaccess”!).