May 13, 2020

The modules/server/request.js of the Salesforce Commerce Cloud defines the querystring in the following way:

1
2
3
4
5
    Object.defineProperty(this, 'querystring', {
        get: function () {
            return new QueryString(request.httpQueryString);
        }
    });

So when accessing request parameters, it will run the queryString.js script, doing quite an expensive transformation of the querystring. Often this happens multiple times, for example with req.querystring.cgid || req.querystring.cid.

This performance impact can be avoided in different ways:

  • cache the result within your custom scripts, like var qs = res.querystring, and access parameters on the existing object, for example qs.cgid

  • cache the result of new QueryString(request.httpQueryString) at the request object

  • create a global custom cache for caching evaluation results of querystrings

The latter two require changes to the modules/server cartridge, which are not always wanted. A combination of the approaches can bring the biggest impact.

Contact