0

Acutually I am redirecting the customers to the Specifc Store based on their geo IP Addresses.

I applied Plugin and Observer also but the same result.

Everthing is fine working, But it cachees I have to flush the cache every time.

Can Anybody help me get out of there.

1 Answer 1

0

You can simply disable full page cache by bin/magento cache:disable full_page but it will kill performance. So I don't recommend to do that.

In case you use Fastly - you can use built-in GeoIP redirect feature. It's possible simply configure that. Just google it.

In other case - the right solution for me is to send an AJAX POST request during the first website visit to the custom endpoint. Something like that:

  1. Customer opens any website page
  2. You have a custom JS script on every page
  3. You check the localStorage.get('geo_ip_processed'). If it's false - send a POST request (POST because the result will not be cached) to the custom endpoint
  4. On the custom backend endpoint, you decide whether the customer should be redirected and where. returns something like [ 'redirect_to' => 'https://website.com/de/' ]
  5. Then your custom JS script writes localStorage.set('geo_ip_processed', true) and redirects the customer to the needed URL. If a redirect is unnecessary, you need to set geo_ip_processed to true anyway.

The magic here is that your website can be fully cached, but the only part with GeoIP detection will not be cached because we use POST request which is not cached in Magento by default.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.