Cache-control: Is it possible to ignore query parameters when validating the cache?

放肆的年华 提交于 2020-01-15 03:33:11

问题


Is it possible to set a cache-control header communicating with a reverse proxy to ignore query parameters in determining what is a unique uri or in short: validate a cache even if some query parameters have changed?

Sometimes query parameters have nothing to do with the rendering of the page at least from a server side perspective. For instance all utm_* variables from Google Adwords. These are needed for the javascript on your page so you don't want to strip them away and redirect to a cached page but at the same time it would be advantageous not to treat two uri's which are basically the same but have different utm_* parameters as unique when communicating with a reverse proxy.

An example:

  1. http://www.example.com/search?sort=price

  2. http://www.example.com/search?sort=price&utm_campaign=shoes

Is there anyway to tell the reverse proxy using the HTTP 1.1 spec (i.e. some type of http header) that it can just treat these two pages as the same?


回答1:


You can filter the query string in vcl_recv and there is also a Varnish module for that [1].

Also, you have to keep in mind that query string parameter order matters in this case [2]

See also this related question [3]

[1] https://www.varnish-cache.org/vmod/querystring

[2] http://cyberroadie.wordpress.com/2012/01/05/varnish-reordering-query-string/

[3] Stripping out select querystring attribute/value pairs so varnish will not vary cache by them



来源:https://stackoverflow.com/questions/19126016/cache-control-is-it-possible-to-ignore-query-parameters-when-validating-the-cac

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!