How long is a Javascript return DNT value good for?

This issue came up on the call.  Clearly the DNT value in an HTTP header applies to that transaction (only). But if I call the JS property, which returns the DNT value that would be sent in an HTTP header at that moment, how long can I treat the answer as being true? We’re no longer tied to a transaction.

Mike proposes that the value is only good for as long as you don’t think it has changed, and that we therefore need an event ‘DNT for your origin has changed’ (I am not sure how we distinguish origins). 

I wondered if this was needed, and whether we could set a reasonable temporal scope on the return value. We toyed with ‘while the page remains open’ but this doesn’t answer the question for service workers.

My colleagues point out that
a) the JS property is cheap, it’s simply checking the base value and exceptions, not doing any disk or network traffic
b) the number of places that the code might take a different branch, depending on the answer, is probably quite small
c) it'd be reasonable to require its value to be stable per turn of the runloop. So if you had a function like so:

function thingy() {
   if (navigator.doNotTrack && navigator.doNotTrack.startsWith("1")) {
       a();
   }
   ...
   if (navigator.doNotTrack && navigator.doNotTrack.startsWith("1")) {
       b();
   }
}

The caller of thingy would know (modulo an exception being raised) that either both A and B got called or neither did.



Given these, I think we should adopt (c) and also say roughly “you don’t need to ‘poll’ this value, but you should check it at the points where your Javascript would branch depending on the answer, and not cache previous returns for any significant length of time”.

Dave Singer

singer@mac.com

Received on Tuesday, 2 May 2017 19:11:54 UTC