Optimizing a Magento online shop's speed

Magento is a very powerful and complex e-commerce solution. One downside of this complexity is Magento's performance which tends to be slow on a shared web hosting environment that hasn't been properly optimized for Magento. Studies have shown a direct correlation between an online shop's speed and its sales volumes. One study that focused on Amazon.com found out that a 100ms delay in the loading time of the online shop's frontpage lead to a 1% decrease of sales. It is thus recommended even for owners of smaller online shops to optimize the shop and its hosting environment for a quick loading time.

The following are some important points which should be considered when selecting and setting up a hosting environment for Magento.

Choosing the right hosting provider and server environment

The «Magento Hosting Partners» listed on the Magento website offer hosting solutions optimized for Magento.

The «Magento Hosting Partners» listed on the Magento website offer hosting solutions optimized for Magento.

Choosing a «Virtual Server» or «Dedicated Hosting» is strongly recommended for hosting a Magento online shop. These types of hosting solutions provide a dedicated server where just one website or online shop will be run on. On a «Shared Hosting» on the other hand, multiple applications or websites are installed on the same server. This means that an online shop installed on such a server has to share ressources with other websites and online shops installed on that same server. This might work out well for a while, but if for some reason another website or online shop hosted on the same server experiences a strong increase in traffic, this will slow down all the other projects hosted on that server as well.

Luckily there are various hosting providers which have optimized their servers for Magento. Many of these hosting providers are registered as «Magento Hosting Partners» and listed on the Magento website. It is recommended to browse through this list when looking for a hosting provider.

Increasing a server's «memory_limit»

The more memory is accessible to Magento, the better. When setting up a Magento server, an online shop owner should ask their hosting provider what amount of memory is available on the server, and set up Magento to use that maximum amount of memory available. On an Apache server this is done by adding the following to the .htaccess file:

php_value memory_limit 1000M

In this example, the memory limit would be set to 1000MB.

Activating gzip- & zlib compression of all files

Before sending data from the server to an online shop's visitor, this data should be compressed, to preserver bandwidth and send less data to the visitor. This can greatly reduce the amount of data transferred to the visitor. To set up this compression on an Apache server, the following has to be added to the .htaccess file:

<IfModule mod_deflate.c>
    SetOutputFilter DEFLATE
</IfModule>

php_flag zlib.output_compression on

Caching queries in the MySQL database

Query caching offers a cache for database query which have to be executed frequently. It's important to understand that Magento sometimes makes up to 300 queries to the database to render just one site. By caching these frequently executed database queries the time to execute these 300 queries can be reduced greatly. To activate query caching, add the following to the my.conf database configuration file:

query_cache_size=32M

If you don't have access to the my.conf file, just ask your hosting partner to make that configuration for you.

Repairing and optimizing database tables

First select all the database tables, then select «Repair Tables» and «Optimize Tables».

First select all the database tables, then select «Repair Tables» and «Optimize Tables».

Occassionally the database tables used by Magento should be repaired and optimized. Installing and uninstalling Magento extensions and making changes in the Magento configuration can leave quite a bit of data waste in the database. To get rid of this waste, the following has to be done in phpMyAdmin:

  • Create a backup of the complete database
  • Select all the tables
  • Successively select the options «Repair Table» and «Optimize Table»

Increase the lifetime of the browser cache

When a visitor visits your Magento online shop for the first time, certain data is saved in the visitor's browers' cache. The next time the visitor opens a page in your shop, this data won't have to be sent again. For example if you have a logo that is displayed in the header of your online shop on every page, this logo will only have to be sent once, and not on every page that the visitor opens. This reduces the amount of data that has to be transferred to the visitor and reduces the loading time of the online shop. To ensure a maximum lifetime of this browser cache, add the following to your Apache server's .htaccess file:

<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType text/css "access plus 1 week"
    ExpiresByType application/javascript "access plus 1 month"
    ExpiresByType application/x-javascript "access plus 1 month"
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType image/x-icon "access plus 1 year"
</IfModule>

Optimizing images displayed in the online shop

Every image that is uploaded to your hosting server, for example product photos or design elements, should be optimized for web display. Also make sure that the images are provided in exactly the resolution that they will later be displayed in. So if you take your product shots on a high resolution SLR camera which shoots at a 3000x3000px resolution, resize those product images before uploading them to your online shop.

Adobe Photoshop, which is often by online shop owner, offers a «Save for the web» function. Additionally there are various freeware applications which can add even more compression to your images. One such application is ImageOptim for Mac OS X. This application usually squeezes a few more percent of the file size from images exported in Photoshop.

Compressing and minimizing Javascript and CSS files

Compression of JS and CSS files should be turned on in every Magento online shop.

Compression of JS and CSS files should be turned on in every Magento online shop.

Magento uses lots of Javacript and CSS to enhance the design and functionality of an online shop. If all these files have to requested individually from the server this greatly increases the loading time of the online shop. Luckily Magento offers a function that can combine, compress and minify these files. Any online shop owner should take advantage of this. To activate the functionality, the following has to be done:

  • Login to your Magento Admin Panel
  • Switch to System -> Configuration -> Developer
  • Make sure that under «JavaScript Settings und «CSS Settings» both options are set to «Yes»

Deactivating the Magento log

Magento keeps a very detailed log file that protocolls everything that happens in your online shop. This is very useful to find bugs during the development phase. But once an online shop has been launched this log isn't important anymore. Furthermore it might slow the shop down because of the many events that get logged. To deactivate this log do the following:

  • Log in to your Magento Admin Panel
  • Switch to: System -> Configuration -> Developer -> Log Settings and set «Enabled» to «No»
  • Switch to: System -> Configuration -> Advanced -> Disable Modules Output and set «Mage_Log» to «Disabled»

Activate Magento's compilation

The compiler is a tool used by Magento which combines various Magento code files that are spread around multiple directories into a single file. This reduces the time that Magento takes to look up and gather all these files. To activate the compiler do the following:

  • Log in to your Magento Admin Panel
  • Switch to System -> Tools -> Compilation and click «Run Compilation Process». The compiler is now activated.

Further optimization possibilities...

This was an overview over the easiest and most often used Magento optimization techniques. There are thousands of other ways to improve a Magento online shop's loading time and configure the hosting environment to work even faster with Magento.

If you are interested in a comprehensive analysis and optimization of your Magento online shop we'd be happy to help you. Contact us for a free consultation and we'll show you what we can do to make your online shop faster.

Other interesting articles:

Back to the blog overview