Source: Aduro Labs Blog

Aduro Labs Blog Speed Up Magento Via Your Htaccess File | Make Magento Fast, Really Fast!

At Aduro Labs we have a number of clients who run large websites on Magento. Magento is an advanced ecommerce platform, and has an awful lot of functions to make selling online easy. Even though it can take some time to make relatively simple changes, it does exactly what it says on the tin.One issue we have found with Magento is its loading speed. Load times are becoming more and more important online with some of the major search engines recommending that websites load as quickly as possible. Google for instance has even produced a tool to help measure your overall page loading time and even tells you exactly what needs to be corrected to improve that time.Before we go any further let's listen to what the head of Google's web spam team; Matt Cutts, has to say about web speed. The video is a bit dated now (2011) however the topics discussed are still valid:So, where do you start with speeding up Magento? The first thing you need to do is to analyse the overall speed of your Magento page, before any changes have been made. We would recommend three tools which can be found below:Google PageSpeed InsightsWebPageTestGTmetrixWe would always recommend using two or three tools to analyse website page speed, as some will give more detail than others and speed scores to vary from tool to tool.We ran the website through the Google PageSpeed Insights first to get an initial overview of the website page speed.As you can see the overall page speed was not a brilliant 38 out of 100, so we knew we had a little bit of work to do.Getmetrix scores your websites page speed in A-F grades and as you can see below the initial results were not great:With theses speed tools telling us exactly what needed to be altered we set to work.Speed Up Magento Via The Admin PanelOne of the issues that the Google PageSpeed Insights tool suggested as a high priority was to merge CCS and Java script files of the website. Now, if you are sat there thinking how on earth do I do that, have no fear!Magento has a few features accessible within its admin panel to allow you to merge CCS and Java script files of the website, which can be found by clicking on the following menu options:System > Configuration > Developer > JavaScript SettingsOnce you have located the JavaScript Settings menu option simply set them to "Yes" and that's it. Simple right.One other feature that can help to increase the loading time of a Magento site overall which again can be found within the admin panel is something called Magento Compiler.Magento Compiler is a module that compiles PHP files that are usually located in different locations and moves them into one single file, which in simpler terms means that they are executed a lot faster because they are all in one place.To find the Magento Compiler simple go to System > Tools > Compilation and once you've found it simply click on Run Compilation Process in the top right hand corner and you're done.Once these changes have been made it would be a good idea to run your site one of the tools mentioned above to see if these changes have made any difference. Once you have a fresh set of results it's time to move onto the more advanced stage.Speed Up Magento via Your .htaccess FileNow a word of caution before we start, this file can do some serious damage! It's incredibly easy to knock a website over (and believe me I know) so please take care. Please take a back up of your htaccess file before making any changes, so if you do crash your website, you can simply just re-upload the original. I even take a back up of a back up I'm that paranoid. :)Step 1: Gzip Compression For MagentoYou will need to enable Gzip Compression. To do this simple find this piece of code and uncomment it:############################################## enable resulting html compression php_flag zlib.output_compression on############################################What I mean by uncomment it is to remove the # from the line (#php_flag zlib.output_compression on) once that is done simple save and re-upload the htaccess file.Step Two: (optional) Compressing CSS and JavaScript filesNext we want to compress items such as CSS and javascript etc. Simply add the following lines of text directly into the htaccess file.############################################## compress text, html, javascript, css, xml:AddOutputFilterByType DEFLATE text/plainAddOutputFilterByType DEFLATE text/htmlAddOutputFilterByType DEFLATE text/xmlAddOutputFilterByType DEFLATE text/cssAddOutputFilterByType DEFLATE application/xmlAddOutputFilterByType DEFLATE application/xhtml+xmlAddOutputFilterByType DEFLATE application/rss+xmlAddOutputFilterByType DEFLATE application/javascriptAddOutputFilterByType DEFLATE application/x-javascript# Or, compress certain file types by extension:<files *.html>SetOutputFilter DEFLATE</files>###########################################For a brilliant round up of why this is important, and with some great illustrations on this step can be found at BetterExplained.comStep Three: Leverage Browser Caching and Expires HeadersThe third thing to do is Leverage Browser Caching and Expires Headers. This piece of code can make a huge difference and will reduce the number of HTTP request, which is a huge benefit for any returning visitors to your website.##############################################<IfModule mod_expires.c># Enable expirationsExpiresActive On# Default directiveExpiresDefault "access plus 1 month"# My faviconExpiresByType image/x-icon "access plus 1 year?# ImagesExpiresByType 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"# CSSExpiresByType text/css "access 1 month?# JavascriptExpiresByType application/javascript "access plus 1 year"</IfModule>############################################In simpler terms when a customer visits your Magento website for the first time, their browser will then fetch all of your images, css files, javascript files, etc found on your website. In a normal situation that happens every time that visitor visits your Magento website.With Expires headers added to you htaccess file you will be informing their browser that the files you specify are not changing until after a set time. This means that your customer's browser won't have to fetch everything, every time they visit your Magento website.We have set them to expire in a month, however you can choose a longer or shorter time scale if you wish.It might be worth looking at each individual file individually and determine how often these files could be changed, from there make a decision how long they can be cached to your customers web browser. You have 7 options:yearsmonthsweeksdayshoursminutessecondsStep Four: 404 ErrorsThis is a very important final step. If you are running a large Magento website with lots of 404 errors, these must be 301'd to a relevant page.If you do find you have a few 404 errors please just don't 301 redirect them to your homepage. Please take the time and make sure that broken product pages are redirected to alternative or relevant products or category pages.Taking control of your 404 errors may not necessarily speed up your site that much but it improves the overall user experience of your website, keeping customers happy!To 301 redirect in Magento simple add the following to your htaccess file:Redirect 301 /broken-url http://www.example.com/new-urlPlease note that you do not have to add the whole broken URL just simply everything after the trailing slash / .Again please take care when adding a 301 to your htaccess and make sure that you test the redirected url to make sure it now redirects to the new required page.If you are unsure exactly where or how to find any 404 errors that your website may have there are a number of tools available such as Screaming Frog or if you have access to a Google Webmaster account they can be found within that as well.Final Magento Speed TestOnce all of the above have been added and configured it's time to see what the improvements are by running another page speed test.As you can see from the above screen shot, we still have a few bits and pieces to finalise but the immediate results are clear. This page has gone from a page speed of 38 to 90, by simply just applying some basic changes to htaccess file and within the Magento admin panel. We will continue to make changes to this site and it's server configuration to get to the mid nineties and hopefully achieve a score of 100 or an A grade.Other Ways To Speed Up MagentoIt pays to play close attention to the number of extensions you have installed within Magento. The more modules or extensions you have the slower the website will load and it pays to carry out a bit of spring clean every now and then and remove extensions or modules you're not using.If however all this htaccess stuff scares you a little there are extensions out there that can do most of it for you however, I have never used them, so it wouldn't be viable for me to say if they're any good. ImagesMake sure your images are optimised, no greater than 92dpi and a minimum of 72dpi and please make sure they are correctly sized before they're added to your website. Try to also save your images as a .png format which will compress images without losing any quality.Content Delivery NetworksOther advanced methods include a CDN or content delivery network and I personally would highly recommend the service from CloudFlair.com. I hope you've found this brief guide to speeding up Magento useful. I hope to add a few more Magento optimisation tips on our blog over the coming weeks so stay tuned for that.With page speed being such an important factor and with large online retailers constantly looking for ways to reduce bounce rate , whilst also keeping their user experience of their website as smooth as possible, it will certainly pay dividends to spend some time looking at your Magento sites overall page

Read full article »
Est. Annual Revenue
$100K-5.0M
Est. Employees
1-25
CEO Avatar

CEO

Update CEO

CEO Approval Rating

- -/100