What is a proxy class?

A proxy class is simply a class that is used in place of another class, almost always for performance reasons. This class sits in front of the other class, and doesn’t instantiate until a function within the original class is called. Proxies instead contain logic for delaying the instantiation process of the original class. So rather than instantiating the class right away, it is only instantiated when a method on that class is called.

The term “proxy” is used in other areas of programming & computing as well. For example, when someone visits yourdomain.com, it’s generally served up by one specific application running on a single web server. But in the past, I’ve created web server proxies. These can basically funnel specific requests to other services in the background. This means that you can create a proxy just for a specific URL of your domain, so that it is served up by an entirely separate application & service.

In this example, we can set up a web server such as Nginx to listen for a specific URL, let’s say slash-blog, and that request can be served up by an entirely separate app, running on a completely different stack.

This is how you would be able to setup Magento as your default service on your main web root, but also have something like Nuxt.js running a Node.js backend for your slash-blog route, or Wordpress running a completely different version of PHP & MySQL on an entirely different web server. The directory structure would not at all need to be located in the same location as your Magento instance, because it’s an entirely different app, running a completely different web stack on a completely separate server!

You can think of proxy classes as being very similar. When a specific class is requested, another class can be served up, and no one else really even needs to know about it. The delaying of the instantiation process of the original class basically makes the class load instantly, so your app can continue to execute without having performance issues.

Complete and Continue  
Extra lesson content locked
Enroll to access all lessons, source code & comments.
Enroll now to Unlock