putyourlightson / craft-blitz

Intelligent static page caching for creating lightning-fast sites with Craft CMS.
https://putyourlightson.com/plugins/blitz
Other
149 stars 36 forks source link

Cache Sprig components #667

Closed andrewfairlie closed 4 months ago

andrewfairlie commented 4 months ago

Support Request

Is it possible to cache Sprig components to improve their performance?

I mean the ones loaded like

index.php?p=actions/sprig-core/components/render&query=&page=2&sprig%3Aconfig=eb9ce109222fb72cf718be545a0dcc92049549ac06a216b29e2aac26c9552505{"siteId"%3A1%2C"template"%3A"_\%2Fcomponents\%2Fsprig-content\%2Farticles"}

I have the following included URI patterns enabled CleanShot 2024-05-22 at 14 05 16@2x

And the following query string setting

CleanShot 2024-05-22 at 14 05 42@2x

And the following nginx config

    gzip_static on;
set $cache_path false;
if ($request_method = GET) {
    set $cache_path /cache/blitz/$host/$uri/$args/index.html;
}
if ($args ~ "token=") {
    set $cache_path false;
}

#- Send would-be 404 requests to the cache path or Craft
location / {
    try_files $cache_path $uri $uri/ /index.php?$query_string;
}

Ideally these partials would be cachable in the same way other pages are for peak performance.

Plugin Version

5.3.1

bencroker commented 4 months ago

No, Sprig requests are never cached, since they are action requests, but you can cache database queries in the Sprig component using Craft’s native cache tags to help reduce their load time.