Web performance is getting more and more attention from web developers and is one of the hottest topic in web development.
Fred Wilson considered it at 10 Golden Principles of Successful Web Apps as the #1 principle for successful web apps.
First and foremost, we believe that speed is more than a feature. Speed is the most important feature. If your application is slow, people won’t use it.
The good news is that some of the most important speed optimizations can be easily done with simple .htaccess rules. These rules can make any website faster by compressing content and enabling browser cache. For more information on .htaccess files, see the .htaccess tutorial.
If you are just looking for the final .htaccess file, jump to the end of this article.
Faster website means more revenue and traffic
For Amazon, every 100 milliseconds delay costs 1% of sales. (Source: Design Fast Websites)
For Google, half a second slowdown resulted in a 20% drop in traffic. (Source: Speed Matters)
Google experiments reached similar results:
Our experiments demonstrate that slowing down the search results page by 100 to 400 milliseconds has a measurable impact on the number of searches per user of -0.2% to -0.6% (averaged over four or six weeks depending on the experiment). That’s 0.2% to 0.6% fewer searches for changes under half a second!
And speed is now a factor contributing to Google Page Rank:
Google, in their ongoing effort to make the Web faster, blogged last month that “we’ve decided to take site speed into account in our search rankings.” This is yet another way in which improving web performance will have a positive impact on the bottom line.
Compress content
Compression reduces response times by reducing the size of the HTTP response.
It’s worthwhile to gzip your HTML documents, scripts and stylesheets. In fact, it’s worthwhile to compress any text response including XML and JSON.
Image and PDF files should not be gzipped because they are already compressed. Trying to gzip them not only wastes CPU but can potentially increase file sizes.
To compress your content, Apache 2 comes bundled with the mod_deflate module.
The mod_deflate module provides the DEFLATE output filter that allows output from your server to be compressed before being sent to the client over the network.
The following rule will gzip all your *.css, *.js, *.html, *.html, *.xhtml, and *.php files:
<ifModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/css text/javascript application/javascript application/x-javascript
</ifModule>
Read more: samaxes