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

Cached Sites using wrong app language #170

Closed sarahschuetz closed 4 years ago

sarahschuetz commented 4 years ago

Describe the bug

I am working on a multisite-project with german and english sites. When the cache is warmed using the "Warm Cache" button in the "Utilities" section, the craft.app.language is set incorrectly and the translations uses the wrong translation file. When the same page is cached just by visiting the page, without prewarming, the language works correctly. Also without cache, the language is correct.

To reproduce

Steps to reproduce the behaviour:

  1. Set the language of the current site to 'de' in the Craft Backend (we have 3 german and 2 english site)
  2. We use lang="{{ craft.app.language |slice(0,2) }}" on the html element.
  3. Without caching: Source Code is <html lang="de"> and translations work correctly
  4. When the page is cached, because it was visited: <html lang="de"> and translations work correctly
  5. Manually clear Blitz cache via Craft Backend
  6. Warm Cache using the "Warm Cache" button in the "Utilities" section
  7. Now the Source Code is <html lang="en"> and translations don't work correctly

Versions

bencroker commented 4 years ago

Are you by any chance using @web in the base URL of the site settings? See the warning about using it here and here.

sarahschuetz commented 4 years ago

No we are not using @web. However we are using other aliases. Are all aliases a problem, or just @web?

bencroker commented 4 years ago

Just @web, as it cannot be correctly calculated from console requests.

Was this issue resolved for you, and if so then how? It may be related, hence I ask.

sarahschuetz commented 4 years ago

@bencroker as said here, I changed my folder path from a relative path to @webroot/blitz/cache. When warming the cache via console the language is set correctly on my local test environment. I will update you as soon as a had a chance to test it on the server as well.

bencroker commented 4 years ago

Great, let me know.

bencroker commented 4 years ago

Please also be sure to test this using the Guzzle warmer.

sarahschuetz commented 4 years ago

Changing the folder path to @webroot/blitz/cache also fixed the problem on our server. All good now 🎉 Thanks for your help!

bencroker commented 4 years ago

Sure thing!