Optimizing magento for speed
2Hats . 5 minutes

Optimizing Magento for Speed and Performance

Magento is a very good ecommerce solution at the same time as they call it ‘an over engineered’ system which is not very light. But can we rule it out from the list of ecommerce softwares we would consider? Definitely not. Reasons are anything from Magento being open source to the community help and plugins’ availability. We help many of our clients with site speed optimization and performance boosting of their webshops. Here we will share some techniques we generally use. Most of these suggestions you can see from Google pagespeed insights.

1. Image Optimization

Make sure all the images used in the site, including banners and product images are saved for web. If you are using photoshop there is an option to save for web and devices. If the product images are high in size that will considerably slow down the site.

2. Leverage Browser caching

Browsers download all assets of a webpage when it loads. Assets like CSS, Images, Javascript etc. Most of these static assetswould be the same for all the pages of that website which the browser need not download again. Using browser caching is, enabling the caching of these files, CSS file for example which will be a single file for the whole website. So the after the first page load the static files will be pulled from the browsers cache making browsing a smooth experience. In Magento we can do this with adding some code to the .htaccess file in the root of the installation.

Browser caching using mod_expires
This is used in most dedicated/vps servers. Add the following code to htaccess and it will enable browser caching.

 

Browser caching with mod_headers
This is the method to use when working on a shared server.

3. Enable Gzip compression.

Read more about what is Gzip compression. Gzip compression allows the web servers to provide lower size files and there by decreasing the page load time. We need to have mod_deflate turned on in Apache. Add the following code to your .htaccess file in the root and check google pagespeed insights or Gtmetrix to see if its working properly.

4. Merge CSS, JS if possible or defer loading of Javascript

This is a tricky part in the process which maynot always be solved on the fly. Magento has a feature to Merge CSS and JS (Goto System > Configuration > Advanced – Developer). You can try merging your JS and CSS here. But after enabling each, please go and check if the site works perfectly as before. Also check the add to cart function and checkout functions as that contains javascript operations. The product page has additional JS. Again this is not a 100% fool proof stuff by just enabling the magento settings. Sometimes you might need to go in and manually merge some files and add it back to page.xml layout file if you really want to merge without conflicts with other javascript files.

Another way of optimization is by deferred and/or async loading javascript. In defer loading the javascript will be loaded asynchronously along with loading page elements. So the rendering of dom elements will not be blocked for the loading and execution of javascript. Which increases speed of delivery of the page initially and users will get to see the page quickly. If a javascript needs to be executed before page load it shouldn’t be defer loaded.

We can achieve this by adding a parameter like this -defer to the javascript include handle like below.

5. Minify CSS, JS and HTML

Minifying CSS, JS and HTML will give us additional gain in saving the page size. There are plugins available like here that will help minifying JS, CSS and even HTML. This will remove all the whitespaces in the css and Js files and reduce considerable amount of size.

6. Use a Content Delivery Network

A content delivery network or CDN is a system of distributed servers that deliver web contents or especially static assets like JS, CSS and Images to a user from a geographically nearer location and there by speeding up the delivery. Lets say a user in India is accessing a website hosted in USA, the content delivery will have the latency to communicate with the server placed at a far location. If the website uses a CDN service which has its servers somewhere in India, then the contents will be delivered to the user from the CDN server in India reducing the latency.

Use a CDN for your site especially if you are targetting global consumers or if your server is hosted somewhere far than your target country.

7. Use Varnish caching to improve delivery performance.

Using varnish is an effective way to improve site performance. Varnish is a web application accelerator. You install it in front of any server that speaks HTTP and configure it to cache the contents. It will increase the delivery speed of the website by multiples.

We can help to speed up your magento store to load in less than 3 seconds. Need help implementing any of these? Contact us here!

blog
Greetings! I'm Aneesh Sreedharan, CEO of 2Hats Logic Solutions. At 2Hats Logic Solutions, we are dedicated to providing technical expertise and resolving your concerns in the world of technology. Our blog page serves as a resource where we share insights and experiences, offering valuable perspectives on your queries.
Aneesh ceo
Aneesh Sreedharan
Founder & CEO, 2Hats Logic Solutions
Subscribe to our Newsletter
Arsha Contact

    Stay In The Loop!

    Subscribe to our newsletter and learn about the latest digital trends.