Support » Plugin: LiteSpeed Cache » IP2Locationm, AJAX Requests etc being cached – Help with ESI

  • Resolved molokini

    (@molokini)


    Hello,

    We have developed a large site that uses AJAX quite heavily to pull in web forms for the user and we are also using WPML. What we are finding is that say for example someone on the UK English site requests the enquiry form, they get returned the UK English string translations, which is fine. But if a German user on the German part of the site also requests that form, they get the form with the English string translations not the German ones. It’s like the AJAX request has been cached.

    We also have problems with Geolocation, we’re using IP2Location and in PHP we query the local database for the location and then using a localised Javascript file insert this into a localised variable for us to use. But sadly it seems that whatever the site language was at the point the GeoIP Location was derived during the cache period, that response is what is always served up to the user regardless of actually where they are.

    We believe the solution to this is ESI, but I am a complete newbie at ESI and I wondered if someone could help either with this problem or point me in the direction of some documentation. I have tried implementing some code I found but it didn’t work.

    As I say the issue isn’t just with IP2Location, but also with AJAX requests in general.

    Many thanks.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hi @molokini, may I know does the AJAX contain any parameter to identify the language or it relies on user’s cookies?

    Also, could you please provide your Report Number, found in WP Admin > LiteSpeed Cache > Report and show us how to reproduce both issues?

    Plugin Support Hai Zheng⚡

    (@hailite)

    Hi @molokini ,

    Based on what you described, yes it prolly will be cached and served wrong cache copy.

    Are your AJAX requests from REST? There is a Cache REST setting, if you turned it off, will it serve correct content for German users?

    Keeping non-cacheable is not an ideal solution obviously. But lets try that first for the first step.

    If true, you can consider to use vary to serve different cache for different users.

    If you are using AJAX to generate different contents, ESI may not help. Even it helps, Vary is still the main factor you will need to fix the issue.

    Thread Starter molokini

    (@molokini)

    Hey guys,

    Thanks for your help.

    The AJAX requests are issued using a standard jQuery AJAX POST request to admin-ajax.php sorry for the slight vagueness on this but I’m not an expert on all this!

    Essentially on the ‘wp’ hook, we’re using IP2Location to look up the user’s IP in a database and storing that in a global variable called $IN_LOCATION. This is then put in a localised variable called IN_VARS which has a number of keys, but IN_VARS.in_location is the one that $IN_LOCATION goes in.

    Sorry if this all sounds bit obvious but I just need to explain what we have as this is an area of my knowledge that is not at expert level by any stretch of the imagination!

    I have set the Javascript file that this is localised into to not be cached but it seems IN_VARS always ends up with cached values, therefore the redirection suggestions end up wrong (as it’s the Javascript that manages the redirections and popups).

    Cookies aren’t used in this instance.

    The report reference is: ZEOOJTDB

    Hope that helps!

    Thanks.

    Could you please join our Slack channel or submit a ticket here for helping us to reproduce the issue? Thanks.

    Plugin Support Hai Zheng⚡

    (@hailite)

    Hi @molokini ,

    I just checked your report number. From your page source code, I can see the IN_VARS js variable you mentioned. Yes as long as it is in source code, it will be cached. Is that IN_VARS manually written/customized by you or a certain plugin?

    IN_VARS does have a number of keys. But looks like it is not a mapping of location to URL. Can you state who makes the redirection? I noticed you have in_location_alt_url which is https://www.***.net/us/ but when I visit the page, I wasn’t redirected to www.***.net/us/. The page kept me in www.***.net.

    I can understand you are not an expert. That is ok. Let’s try to fix it. No worry.

    Thread Starter molokini

    (@molokini)

    Hello,

    Yes IN_VARS is only written to by our functions.php no third party plugins.

    The redirect doesn’t occur because the code is disabled because it was giving all sorts of wrong dialogs suggesting the user is in Germany when they weren’t for example.

    Hope that helps and thanks for understanding my lack of expert knowledge!

    Thanks

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘IP2Locationm, AJAX Requests etc being cached – Help with ESI’ is closed to new replies.