6 Tips for Making Magento Production Ready

6 Tips for Making Magento Production Ready

Oct 22

  • Created: Oct 22, 2010 2:53 PM

During the development of your Magento eCommerce store, performance usually takes a back seat to functionality and design. However, after you’ve installed all of your extensions and have checked the spelling on your last cms page, you’ll want to focus your attention on making your shop as responsive as possible for your customers. Granted, it pays to have a terrific hosting provider that understands how to optimize the server environment, but there are also some things you can do on your end to minimize latency and make your shop run as efficiently as possible.

Tip 1: Tweak your .htaccess file:

Magento’s .htaccess file comes pre-configured with a few tweaks to make your pages load faster, but because hosting environments differ, many of these are commented out or set to low defaults.

1. Turn on output compression

mod_deflate is enabled on all of our servers. This module compresses your text-based files prior to sending them over the network. The customer’s browser then automatically uncompresses them prior to displaying them to the user. To enable this uncomment the appropriate lines as follows:

<IfModule mod_deflate.c>

## enable apache served files compression
## http://developer.yahoo.com/performance/rules.html#gzip

 # Insert filter on all content
 SetOutputFilter DEFLATE
 # Insert filter on selected content types only
 AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript

 # Netscape 4.x has some problems...
 BrowserMatch ^Mozilla/4 gzip-only-text/html

 # Netscape 4.06-4.08 have some more problems
 BrowserMatch ^Mozilla/4\.0[678] no-gzip

 # MSIE masquerades as Netscape, but it is fine
 BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

 # Don't compress images
 SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary

 # Make sure proxies don't deliver the wrong content
 Header append Vary User-Agent env=!dont-vary


2. Enable far-future expires

Some content, such as images and css, don’t change all that often. For content such as this, you can improve performance by taking advantage of a web browser’s caching behavior. Setting far-future expires headers will allow web browsers to cache images and other static files so that upon subsequent visits, they won’t have to be re-downloaded.

<IfModule mod_expires.c>

## Add default Expires header
## http://developer.yahoo.com/performance/rules.html#expires

 ExpiresActive On
 ExpiresDefault "access plus 1 year"


Tip 2: Refresh your indexes

Magento keeps indexes of some of your data in special tables to make queries more efficient. When you were developing your store, you were adding and deleting products, categories, urls, etc. This activity causes your indexes to have gaps and stale data. When you’re ready to go live, you’ll want to refresh all of your indexes in order to rebuild those tables.

There are two ways to do this: from your Admin dashboard or from the command line. To rebuild your indexes from your Magento Admin panel, just go to System > Index Management, select All, select Reindex Data, and then click Submit.

It’s also possible to rebuild your indexes from the command line using the shell tools included in Magento versions 1.4 and higher. These tools are located in your MAGENTO_ROOT/shell/ directory and can be run with a call to php’s command line interface:

$ php -f indexer.php help
Usage:  php -f indexer.php -- [options]

 --status <indexer>            Show Indexer(s) Status
 --mode <indexer>              Show Indexer(s) Index Mode
 --mode-realtime <indexer>     Set index mode type "Update on Save"
 --mode-manual <indexer>       Set index mode type "Manual Update"
 --reindex <indexer>           Reindex Data
 info                          Show allowed indexers
 reindexall                    Reindex Data by all indexers
 help                          This help

 <indexer>     Comma separated indexer codes or value "all" for all indexers

As you can see, the same functionality that can be found in the Admin panel under Index Management can be found here. To rebuild all of your indexes, just enter:

$ php -f indexer.php reindexall

Tip 3: Turn on caching

When you’re developing your site, you probably turned off Magento’s native cache so that you would be able to see your design changes instantly. Now that you’ve finalized your design work, make sure you turn the cache back on. This improves performance 5-10 times over the cache being off.

Ever wonder what gets cached? Here’s an overview:

  • Configuration files (xml)
  • Layouts (xml)
  • HTML blocks for Top Navigation, and Footer
  • Translations stored as an array
  • Data collections for Website, Store, and Store View

Tip 4: Use the Flat Catalog feature

Magento makes heavy use of the EAV model for storing customer, product, and category data in its database. The main benefit of the EAV model is that it allows for completely extensible attributes for those objects. The main drawback is that those attributes are stored in multiple tables rather than one very large table. This means that SQL queries need to be longer and more complex. Using the Flat Catalog feature creates new tables where each row contains all of the necessary data about a product or category. You can imagine that this makes the SQL queries much more efficient.

The Flat Catalog for Categories should be used for all Magento shops. The Flat Catalog for Products only begins to show a performance benefit once you’ve reached the 1000 SKU point. You can enable both of these in the back end:

  1. Go to System > Index Management and make sure “Product Flat Data” and “Category Flat Data” are built and ready.
  2. Go to System > Configuration > Catalog > FrontEnd and select “Yes” for Use Flat Catalog Category and (if desired) Use Flat Catalog Product.

Tip 5: Enable the Mage Compiler

This is a new feature introduced in version 1.3.2.x and bundled with 1.4.x, although it is still listed as “beta”. To understand how this feature can help improve your site’s performance, you have to understand what happens when a browser requests a URL from Magento. By default, and for every request, magento will look in the following directories, in the following order:


This is what gives you, the developer, the wonderful ability to override and extend Magento to your heart’s content. If you want to change or modify some class, you just put your code in app/code/local/ and Magento will find it first and run it instead of the core definition in app/code/core.

As great as this is, it results in a great deal of disk I/O for every request. That’s where the Mage Compiler comes it. It essentially copies all of the class definitions and code found under app/code into a singe directory: includes/src/. It then gets rid of all of the other include paths and replaces them with the one. This way, Magento only needs to search one directory rather than four for each request.

It’s important to compile after you’ve finished installing your modules and developing your custom code if you want this to work properly. This too can be enabled either in the Admin panel or on the command line. In the Magento Admin, go to System > Tools > Compilation, and click Run Compilation Process. To run from the command line, use the following syntax (script is also located in the MAGENTO_ROOT/shell directory):

$ php -f compiler.php help
Usage:  php -f compiler.php -- [options]

  state         Show Compilation State
  compile       Run Compilation Process
  clear         Disable Compiler include path and Remove compiled files
  enable        Enable Compiler include path
  disable       Disable Compiler include path
  help          This help

Tip 6: Make use of parallel downloads to speed page rendering

Most web browsers limit the number of concurrent downloads to around 4 for each unique URL found in a web page. If all of your content is coming from the same host, this limitation can introduce unnecessary delays in rendering the page. You can trick the browser into downloading your content in parallel by using Pointer Domains and Magento’s base url settings.

Let’s say your awesome eCommerce store is located at http://www.example.com/. Your media, skin, and javascript URLs will therefore be http://www.example.com/media, http://www.example.com/skin/, and http://www.example.com/js/, respectively. What you want to do is create different host names for your media, skin, and js URLS that point to the same Magento installation as the www host.

You can do this in your Siteworx control panel under Hosting Features > Domains > Pointer Domains. Create pointer domains called media.example.com, js.example.com, and skin.example.com. Or, you can just create static.example.com. Next, log in to your Magento Admin panel and go to System > Configuration > Web, and change the secure and unsecure base urls for the media, skin, and js options to the pointer domains you just created. Your final configuration should look like the following:

Base URL: http://www.example.com/
Base Link URL: http://www.example.com/
Base Skin URL: http://skin.example.com/skin/
Base Media URL: http://media.example.com/media/
Base Javascript URL: http://js.example.com/js/

Now, go load your page. If you watch the status bar, you’ll notice that your static content, such as images and javascript, is being pulled from the domains you just created, while the main HTML is being pulled from the www URL. In reality these are all located on the exact same server, but the benefit is on the client side, and they don’t need to know that.

  • Pingback: The 54 Most Useful Magento Articles of All Time | @nexcess()

  • http://www.cloudstaff.com/ Alta Noble

    Thank you for sharing this very relevant article. Magento developers are surely delighted with this very helpful information.

  • Petrică Martinescu

    Thank you, great source of information.

  • http://thomasbacon.com/ Thomas Bacon

    One suggestion for Tip #6 – You should set the alternate Base URLs for the Store view of your site, NOT in Default Config. In my experience, that will break some admin functionality, for example the CMS WYSIWYG editor functions.

    If you set it on your store view only, it will only affect the website frontend.

  • Pingback: 6 Tips for Making Magento Production Ready | Ma...()

  • Gregory Wiktor

    yeah the caches get all wonky, especially if you modify your hostname… I found that I needed to do a cache clear in the command line, as well as dump my local browsers cookies… then was ok… but yes, even the admin login can freak out a bit especially after a base_url change…

  • http://www.treklightgear.com/ Seth Haber | Trek Light Gear

    Is Tip 6 still valid? I tried setting it up on my site and I get the error: Font from origin ‘http://skin.****.com’ has been blocked from loading by Cross-Origin Resource Sharing policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://www.****.com’ is therefore not allowed access.

  • bnugent

    Hi Seth. You can try adding something similar to the following to your .htaccess file to allow cross-origin resource sharing for fonts:

    Header set Access-Control-Allow-Origin "*"


    Modify as needed for other file types. Check out the following link for more information about CORS: