Cert++
Close

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 APIWhen its functionality is enough
Shopper API with hooksOnly when a Shopper API exists but lacks data or functionality you need
Custom APIOnly when no equivalent Shopper API exists

Hooks add dependencies and extra request overhead, so use them only when the benefits outweigh these costs.

B2C Commerce Developer Study Guide

Checklist progress

0/237Learned

Given code that violates documented best practices, identify the issues and modify the code to conform with best practices including performance and scalability

0/11

Prepare for the Exam

Play Today's Certle

Study Community

Ask questions and get the latest info from other B2C Commerce Developer studiers.