Performance cost of hook customizations
Key Takeaway
Every hook makes its Shopper API call slower, so keep hook code lean. When a hook modifies a response, work with the web object instead of loading persistent objects with calls like ProductMgr.getProduct().
Hooks are custom Script API functions (before, after and modifyResponse) that change or extend what an existing Shopper API resource does. Every hook adds your code on top of the platform's own API logic, so an API call with hooks is always slower than the same call without them. After you add a hook, you own its performance, so hook code must be lean, cache-aware and tested.
When to use hooks
When you build a feature, you choose between three options: out-of-the-box Shopper APIs, Shopper APIs with hooks, or Custom APIs.
| Use it | |
|---|---|
| Out-of-the-box Shopper API | When its functionality is enough |
| Shopper API with hooks | Only when a Shopper API exists but lacks data or functionality you need |
| Custom API | Only when no equivalent Shopper API exists |
Hooks add dependencies and extra request overhead, so use them only when the benefits outweigh these costs.