sulu icon indicating copy to clipboard operation
sulu copied to clipboard

Cache Url Normalization for tracking query parameters

Open luca-rath opened this issue 2 years ago • 1 comments

Problem description

If a request contains query parameters, the http cache will generate a new cache for the given set of parameters. But there are some parameters (mostly tracking parameters) which don't affect the output of sulu at all, therefore they should probably be ignored for better performance.

UTM parameters

  • [ ] utm_id
  • [ ] utm_source
  • [ ] utm_medium
  • [ ] utm_campaign
  • [ ] utm_term
  • [ ] utm_content

Google Ads

  • [ ] gclid (Google Click ID)

Feel free to suggest other parameters in the comments

luca-rath avatar Apr 07 '22 11:04 luca-rath

For varnish something like the following can added to our example vcl in sulu/sulu and the sulu docs: https://blog.rac.me.uk/2010/03/03/normalizing_the_url_in_varnish/

For the Symfony cache I think it is simple by removing specific query parameter over the SuluHttpCache class and override there the handle(Request $request)

public function handle(Request $request, int $type = HttpKernelInterface::MAIN_REQUEST, bool $catch = true): Response
{
    if ($type === HttpKernelInterface::MAIN_REQUEST) {
        foreach ($this->removeQueryParameters as $removeQueryParameter) {
            $request->query->remove($removeQueryParameter);
        }
    }
    
    return parent::handle($request);
}

To make removeQueryParameters extendable it can be injected in the constructor, our defaults should be provided as a constant on the SuluHttpCache.

alexander-schranz avatar Apr 07 '22 14:04 alexander-schranz