Search⌘ K

Proxy Pattern

Explore the proxy pattern in JavaScript structural design patterns. Learn how a proxy object controls access to another object, reduces load, and caches results. Understand practical use cases and implementation to optimize resource-heavy tasks like network requests.

What is the proxy pattern?

As the name implies, the proxy pattern is a structural pattern that creates a proxy object. It acts as a placeholder for another object, controlling the access to it.

Usually, an object has an interface with several properties/methods that a client can access. However, an object might not be able to deal with the clients’ requests alone due to heavy load or constraints such as dependency on a remote source that might cause delays (e.g., network requests). In these situations, adding a proxy helps in dividing the load with the target object.

The proxy object looks exactly like the target object. A client might not even know that they are accessing the proxy object instead of the target object. The proxy handles the requests from ...