Magento Hole puch With Varnish

Magento Hole puch With Varnish

July 23, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento Hole puch With Varnish

Enhancing Magento Performance: Excluding Dynamic Content from Varnish Cache

Dear Rajesh,

I’m glad to hear that you’ve successfully installed and configured Varnish 3.x for your Magento store on Ubuntu! Enabling full page caching is a great first step towards improving your site’s performance and reducing server load. However, I understand that you want to exclude certain dynamic blocks from the cache while keeping other parts cached for better optimization.

Why Exclude Dynamic Content?

Excluding dynamic content like user-specific data, shopping cart totals, or order summaries allows Varnish to cache static content more efficiently. This reduces the number of requests hitting your backend server and improves response times for frequent visitors.

How to Exclude Specific Blocks in Magento

Since you’re not using Magento’s default caching techniques and have disabled them, we’ll need to approach this manually through .vcl files (Varnish Configuration Language). Here’s a step-by-step guide:

  1. Identify the dynamic block IDs: First, determine the ID of the dynamic blocks you want to exclude from Varnish cache. You can find these in your Magento theme files or using browser developer tools.

  2. Edit your default.vcl file: The default.vcl file is usually located at /etc/varnish/default.vcl. Open this file with a text editor like nano:

    sudo nano /etc/varnish/default.vcl
    
  3. Add a custom VCL file for Magento: Create a new file specifically for your Magento store to keep the configuration clean and separate from other sites if you’re running multiple ones on the same server.

    sudo cp /etc/varnish/default.vcl /etc/varnish/magento.vcl
    
  4. Configure cache exclusion: In the magento.vcl file, locate the sub vhost_magento block and add the following lines inside it to exclude your dynamic blocks:

    sub vhost_magento {
        # Exclude specific blocks from Varnish cache
        if (req.url ~ ".*block-id-1|.*block-id-2") {
            return(pass);
        }
    }
    

Replace block-id-1 and block-id-2 with the actual IDs of the dynamic blocks you want to exclude.

  1. Update your Varnish configuration: Open your main Varnish configuration file, usually located at /etc/varnish/varnish.conf, and update the vcl_file parameter to use your new magento.vcl:

    vcl_file = "/etc/varnish/magento.vcl"
    
  2. Restart Varnish: Save all changes, exit the editor, and restart the Varnish service for the changes to take effect:

    sudo systemctl restart varnish
    

Conclusion

Excluding dynamic content from your Magento store’s Varnish cache is a powerful way to optimize performance without sacrificing the user experience. By following these steps, you can ensure that only essential static content is cached, reducing server load and improving response times for frequent visitors.

Remember to monitor your Varnish statistics regularly to ensure that the excluded blocks are indeed being bypassed as expected. If needed, adjust the block IDs or consult Magento’s documentation on caching for further customization options.

At Laravel Company, we specialize in helping businesses like yours optimize their e-commerce infrastructure and improve performance through strategic caching solutions tailored to their needs. Don’t hesitate to reach out if you require more advanced configurations or expert guidance.

Happy optimizing!

Best, [Your Name] Senior Developer & Technical Blogger Laravel Company

Checkout Cache Performance Themes

Our network