putyourlightson / craft-sprig

A reactive Twig component framework for Craft CMS.
https://putyourlightson.com/plugins/sprig
MIT License
129 stars 9 forks source link

Blitz Cache and Sprig Query Params #397

Closed svondervoort closed 1 week ago

svondervoort commented 1 week ago

Support Request

We are using Sprig in combination with Blitz Cache and noticed when caching a page with a Sprig include the sprig component does not pick up any of the query params in the URL.

The Sprig include code is:

{{ sprig('_pages/search-page/partials/index/sprig/results.twig', {}, {'s-trigger': 'load, refresh'}) }}

Even stranger is that when we try to change any of the query params it forces/redirects you back to the cached version (with different query params) of that page. This does not happen when Blitz Cache is disabled.

We are not sure if this is a configuration issue on our side or maybe a misunderstanding.

Here is a link to a video showcasing the scenario above: https://vimeo.com/1019780072/5d0a251c31

Application Info

Installed Plugins

Plugin Version

3.5.0

bencroker commented 1 week ago

What is the Query String Caching plugin setting set to? And do you have any redirect tags in your Sprig component?

svondervoort commented 1 week ago

The Query String Caching setting is set to "Cache URLs with unique query strings as unique pages" which makes it kind of weird. And we don't have redirect tags inside the Sprig component.

bencroker commented 1 week ago

Are you using server rewrites and, if so, have you added the correct rewrite for Cache URLs with query strings as unique pages?

svondervoort commented 1 week ago

I checked and can confirm we are using the first of the NGINX server rewrites with the $args. The video is of a local environment, but this also happens on the staging environment.

bencroker commented 1 week ago

So I’m not sure why the redirect is happening, but in general I think it’s a bad idea to cache search results as it can result in the cache store being flooded with both legitimate search queries and spam queries. I realise this doesn’t fully answer your question, but would excluding the search results page from being caching should resolve this for you?

svondervoort commented 1 week ago

Yes thats what we did in the end, exclude the pages that have the queries because of the reason you are describing. Thanks anyway for try to figure it out :)