itpp2012 Wrote:
-------------------------------------------------------
> Use curl to find out exactly what the timestamp is before/after
> caching, it might be as simple as chrome not doing something it
> should.
Crafted up this to get the last modified timestamp
function fetchHeader(url, wch) {
try {
var req=new XMLHttpRequest();
req.open("HEAD", url+'?='+Date.now(), false);
req.send(null);
if(req.status== 200){
return req.getResponseHeader(wch);
}
else return false;
} catch(er) {
return er.message;
}
}
Then I do
lastModified = fetchHeader(u,'Last-Modified');
if(lastModified != getCookie(u)){
fc = '?='+Date.now()+'';
document.cookie=u+'='+lastModified+'';
}
and apply the fc variable to the main url in my MAIN ajax request to get the new data and then re-set the cookie.
For getcookie im using:
function getCookie(name) {
var value = "; " + document.cookie;
var parts = value.split("; " + name + "=");
if (parts.length == 2){return parts.pop().split(";").shift()}else{return''}
}
Works perfect so far. And If i have 2000 KB's of data in my npcdata.txt only 409 bytes are used to check the last modified date, no performance issue except for 1 extra request each time just to check. (And it's only 409 bytes!)
This works great for my game as I need to store a TON of NPC text, etc for the game worlds and if I need to edit any they'll be updated live.
-------------------------------------------------------
> Use curl to find out exactly what the timestamp is before/after
> caching, it might be as simple as chrome not doing something it
> should.
Crafted up this to get the last modified timestamp
function fetchHeader(url, wch) {
try {
var req=new XMLHttpRequest();
req.open("HEAD", url+'?='+Date.now(), false);
req.send(null);
if(req.status== 200){
return req.getResponseHeader(wch);
}
else return false;
} catch(er) {
return er.message;
}
}
Then I do
lastModified = fetchHeader(u,'Last-Modified');
if(lastModified != getCookie(u)){
fc = '?='+Date.now()+'';
document.cookie=u+'='+lastModified+'';
}
and apply the fc variable to the main url in my MAIN ajax request to get the new data and then re-set the cookie.
For getcookie im using:
function getCookie(name) {
var value = "; " + document.cookie;
var parts = value.split("; " + name + "=");
if (parts.length == 2){return parts.pop().split(";").shift()}else{return''}
}
Works perfect so far. And If i have 2000 KB's of data in my npcdata.txt only 409 bytes are used to check the last modified date, no performance issue except for 1 extra request each time just to check. (And it's only 409 bytes!)
This works great for my game as I need to store a TON of NPC text, etc for the game worlds and if I need to edit any they'll be updated live.