Skip to content
Webstair Technology home Start a project
Magento Development

Enhance Your Magento Store Performance with Practical Code Examples

By Webstair Technology · Published 18 May 2025 · Updated

Enhance Your Magento Store Performance Tips, Tricks, and Code Examples

A slow Magento store makes shopping harder. This guide covers practical ways to improve performance, with examples for Magento 2.4.

Before you start: back up your store, try every change on staging and measure speed before and after. Run Magento commands from its root folder, as the user that owns the Magento files. Server paths and settings below are examples that you must adjust. We have not run these examples against your store or server.

1. Enable Full Page Caching

Full page cache stores the generated HTML of cacheable pages, so Magento does less work for repeat requests. Images, CSS and JavaScript are cached separately by the browser, web server or CDN. Adobe also publishes performance best practices for Commerce.

bin/magento cache:status
bin/magento cache:enable full_page

# Clear this cache only when you need to
bin/magento cache:clean full_page

2. Keep Indexes Up to Date

For most live stores, set indexers to update on a schedule and make sure Magento's cron jobs run. A full reindex is not something to run routinely, and it can load a busy server.

# Add Magento's cron jobs (check for existing entries first)
crontab -l
bin/magento cron:install

# Update indexes on a schedule, then check them
bin/magento indexer:set-mode schedule
bin/magento indexer:status

# Only when an index needs rebuilding
bin/magento indexer:reindex
Need help with Magento or Adobe Commerce?Get a free quote →

3. Minify CSS and JavaScript

Minifying removes unneeded characters from files. Merging CSS can help some stores and hurt others, especially with HTTP/2, so measure before keeping it. The Developer section of the admin configuration is hidden in production mode, so these examples use the command line.

bin/magento config:set dev/css/minify_files 1
bin/magento config:set dev/js/minify_files 1

# Optional: test the effect before keeping it
bin/magento config:set dev/css/merge_css_files 1

# Production mode: rebuild static files
bin/magento setup:static-content:deploy
bin/magento cache:flush

4. Use Varnish Cache

Varnish is a separate server program that can serve cached pages quickly. Changing the Magento setting alone does not install or start it. You also need to install a version that your Magento release supports, route traffic through it and load the configuration file (VCL) that Magento generates. This example assumes Varnish 6 and a web server listening on port 8080 on the same machine. Handle HTTPS in front of Varnish.

bin/magento config:set system/full_page_cache/caching_application 2

bin/magento varnish:vcl:generate \
  --export-version=6 \
  --backend-host=127.0.0.1 \
  --backend-port=8080 \
  --access-list=127.0.0.1 \
  --output-file=var/default.vcl

bin/magento cache:flush

Review the generated file, install it in your Varnish configuration and restart or reload Varnish. Then check that pages are being served from the cache.

5. Optimize Images with WebP

WebP files are often smaller than JPEG files. This command makes WebP copies of JPEG images in the pub/media/wysiwyg folder and keeps the originals. It overwrites an existing WebP file with the same name, including when two images differ only by extension.

find pub/media/wysiwyg -type f \( -iname '*.jpg' -o -iname '*.jpeg' \) \
  -exec sh -c 'cwebp -q 80 "$1" -o "${1%.*}.webp"' _ {} \;

Making copies does not make your store use them. Update your content or image delivery to serve the WebP files, then compare quality and size. Product images need to be handled through your catalog, theme, CDN or an image extension.

6. Control Log File Growth

Large log files use disk space. This does not usually make pages faster, but a full disk can stop a store. On a Linux server you can rotate Magento's log files with logrotate. Replace the path with your own, and check that your host does not already rotate these files.

/var/www/magento/var/log/*.log {
    daily
    rotate 14
    compress
    delaycompress
    missingok
    notifempty
    copytruncate
}

Save it as /etc/logrotate.d/magento and test it with logrotate -d /etc/logrotate.d/magento. Your server may also need a su line for the log folder owner. A few log lines can be lost while a file is copied and emptied. Do not delete database tables by hand to clean up logs. Find the cause of repeated errors too.

7. Use a Content Delivery Network (CDN)

A CDN serves files from locations nearer to your visitors. After setting up the CDN with your provider, go to Stores > Configuration > General > Web > Base URLs (Secure). Set Secure Base URL for Static View Files and Secure Base URL for User Media Files to the matching CDN addresses. Leave the main store base URL unchanged. Check the unsecure settings too if your store uses them.

8. Upgrade to a Supported Magento Version

Newer releases include security fixes and may include performance improvements. An upgrade can break extensions and custom code, so follow Adobe's upgrade guide for your edition and version. First check the required PHP, database, search and other server versions, take a backup and complete a full test on staging.

The outline below is for Magento Open Source. Replace TARGET_VERSION with the release you have chosen. Adobe Commerce uses different packages and steps.

bin/magento maintenance:enable

composer require magento/product-community-edition=TARGET_VERSION --no-update
composer update

bin/magento setup:upgrade
bin/magento setup:di:compile
bin/magento setup:static-content:deploy
bin/magento cache:flush

# Run only after every command above has succeeded and checks pass
bin/magento maintenance:disable

Run the commands one at a time and stop if any of them fails. Your Composer files may need further changes for the new release.

9. Lazy Load Images Below the Screen

Modern browsers can delay loading images without extra JavaScript. Use real image addresses, add useful alternative text and include the image size to help prevent layout movement. Do not lazy load the main image that is visible when the page opens.

<img src="/media/wysiwyg/size-guide.webp"
     alt="Size guide showing chest and waist measurements"
     width="800" height="600"
     loading="lazy">

10. Monitor and Analyze Performance

Use PageSpeed Insights to review page experience and a server monitoring tool, such as New Relic, to find slow requests and database queries. Check home, category, product, cart and checkout pages, and compare results under similar conditions.

Conclusion

Performance work is ongoing. Make one change at a time, measure its effect and keep your store supported. Results depend on your catalog, extensions, theme, hosting and traffic.

Need help with a slow store? Contact Webstair Technology.

Webstair Technology
Web, eCommerce and mobile development in Ahmedabad, India.

Need help with Magento or Adobe Commerce?

Send a few lines about your project. You can ask for a free quote right here, without leaving this page.

  • For store owners and agencies
  • Name, email, phone and project details are required

Or call +91 82005 38671, Monday to Friday, 9 to 5 IST.

Call usGet a free quote