ostark / upper

Integrates Edge Caches like Fastly, KeyCDN, Cloudflare and Varnish with Craft.
MIT License
102 stars 22 forks source link

Craft's cpresources are cached by default, but it causes some problems #52

Closed RedLucas closed 2 years ago

RedLucas commented 3 years ago

Currently using Craft 3.6.18 and Upper 1.8.0 for Cloudflare enterprise. We use Servd as our host.

What I have been seeing is that when we do new deploys on Servd (a release), it will regenerate the cpresources files, but at times the files aren't ready yet when one of our content editors visit the site, and certain cpresources css and js files end up returning a 404.

After each deploy, we do do a clear-caches/cp-resources and clear-caches/upper-purge-all but it doesn't seem to fix the issue.

The results are seemingly random cases of control panel pages not having all their styles, or lacking functionality because of missing JS.

I took a look at on EventRegistrar::registerFrontEndEvents() and it seems to be checking if it's a CP request, but I wish it could also exclude the cpresources. I don't think there's a method on the request class that provides an easy result to this, but if there is I'd appreciate it.

Ideal outcome: There's an upper setting in the upper.php settings file that allows me to exclude cpresources from the cache-control header, or maybe there's some direction of how I can work around this problem.

johndwells commented 2 years ago

@RedLucas FWIW I see this in Servd's releases without Upper. You might want to raise this with Matt.

ostark commented 2 years ago

@RedLucas @johndwells

To me, the 404s you experience are not related to the HTTP caching.

1.) I see no reason to clear the cp-resources "cache" (guess that are the entries in the resourcepaths table) on every deploy.

2.) With Cloudflare you can define if the query parameter is used as a cache key or not

3.) With Cloudflare's page rules should be able to adjust the cache behavior for different url patterns