Q:

Javascript - Issue with caching and cookies

I am getting quite a frustrating issue with JavaScript and Cookies on cached pages.
I got the following JS code:
function getCookie(cname) {
    var name = cname + "=";
    var ca = document.cookie.split(';');
    for(var i=0; i<ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1);
        if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
    }
    return "";
}
    if (!getCookie("lang") == "{{Lang}}"){
        document.reload();
    }

{{Lang}} is replaced with the very same cookie on the backend with PHP.
$template = str_replace("{{Lang}}", $lang, $template);

But that is not really relevant since that part works as intended.
The issue is that when the user visits a cached page.
The JS previously mentioned becomes
function getCookie(cname) {
    var name = cname + "=";
    var ca = document.cookie.split(';');
    for(var i=0; i<ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1);
        if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
    }
    return "";
}
    if (!getCookie("lang") == "FR"){
        document.reload();
    }

The issue is that the page does not refresh even though the Chrome Dev tools quite clearly say that the cookie lang is set to "EN", not "FR".
Is there a method around this caching issue?

A:

The not equal comparison in JS is !=, so
getCookie("lang") != "FR"

