最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Language does not switch while cache is enabled

programmeradmin2浏览0评论

At my website I have a button when pressed PHP script through ajax write session variable to change language and reload page. But when I enable caching every time is loading default language. When cache is disabled everything is OK.

How translations do big pages with caching?

At my website I have a button when pressed PHP script through ajax write session variable to change language and reload page. But when I enable caching every time is loading default language. When cache is disabled everything is OK.

How translations do big pages with caching?

Share Improve this question asked Apr 21, 2020 at 15:11 SahasrarSahasrar 263 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

If you have any kind of caching enabled on a site with Wordpress, IMHO, it's probably best to use cookies instead of session variables, because with caching enabled, the user's request for a page may not even hit the server at all — so the session var isn't even being read.

What I typically do is use cookies — both setting AND reading them on the front end via ajax. You could dynamically load the new language content that way.

––-––––-

Adding on to answer your second question. If you look at a plugin like WPML or something similar, they are actually creating duplicate content in many cases. So a site might be mydomain/en for English and mydomain/es for Spanish. Each endpoint is cached separately. Some cookies are probably set as well, but when you switch languages with WMPL, you are actually redirected to a different page, not the same page with different language content... if that makes sense?

发布评论

评论列表(0)

  1. 暂无评论