Give precedence to `Last modified:` field when evaluating "age" if lists

Available network information is not very reliable and should be
used only when `Last modified:` is not available.
This commit is contained in:
Raymond Hill 2023-10-27 21:09:49 -04:00
parent ed4b31931a
commit 07ac27e07b
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 7 additions and 5 deletions

View File

@ -56,6 +56,7 @@ const resourceTimeFromXhr = xhr => {
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Age // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Age
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Date // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Date
let networkTime = 0; let networkTime = 0;
if ( assetTime === 0 ) {
const age = parseInt(xhr.getResponseHeader('Age'), 10); const age = parseInt(xhr.getResponseHeader('Age'), 10);
if ( isNaN(age) === false ) { if ( isNaN(age) === false ) {
const time = (new Date(xhr.getResponseHeader('Date'))).getTime(); const time = (new Date(xhr.getResponseHeader('Date'))).getTime();
@ -63,6 +64,7 @@ const resourceTimeFromXhr = xhr => {
networkTime = time - age * 1000; networkTime = time - age * 1000;
} }
} }
}
return Math.max(assetTime, networkTime, 0); return Math.max(assetTime, networkTime, 0);
} catch(_) { } catch(_) {
} }