lundi 1 mai 2017

Disable browser caching for frequent page updates

I am building myself a control panel for servers of mine, and I'm checking if they are online with a small image on the servers themself. This is the JavaScript:

function checkServerStatus()
{
    var img = document.body.appendChild(document.createElement("img"));
    img.onload = function()
    {
        console.log("online");
    };
    img.onerror = function()
    {
        console.log("offline");
    };
    img.src = "http://ift.tt/2pmjOSl";
}

The problem is that the browser caches the result, which makes only the first load a true result. When I turn off the server and hit the refresh button which calls the checkServerStatus() function, it comes up as online. Using meta tags like the ones listed below does not solve the problem.

Meta tags:

<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />




Aucun commentaire:

Enregistrer un commentaire