Closed igrigorik closed 7 years ago
While I think "if (saveData === 'on')" is a little less elegant than "if (saveData) {...}, " I don't want to paint ourselves into a corner. I can easily imagine adding the value 'extreme' in the future.
I think a change in the saveData value should fire an onchange event, as some people do toggle the Data Saver setting in Chrome a fair bit.
While I think "if (saveData === 'on')" is a little less elegant than "if (saveData) {...}, " I don't want to paint ourselves into a corner. I can easily imagine adding the value 'extreme' in the future.
Technically, it doesn't have to. We can easily expose different JS-land attributes for each enum value, instead of asking developers to compare strings. Also, stepping back, do you envision more values in the header, and what would they be?
I think a change in the saveData value should fire an onchange event, as some people do toggle the Data Saver setting in Chrome a fair bit.
sgtm.
So you're saying do something like "if (saveData) { if (saveDataExtreme) { ... }}" ? That seems fine to me.
The only additional value we've considered is something along the lines of "extreme" to indicate that data is extremely expensive (e.g., when roaming) and so the absolute minimal page should be served. This is in contrast to "on," which indicates that the user is still interested in an almost full fidelity page, but would appreciate data reductions that don't interfere too much with the experience.
Interesting. What's the current thinking for where and how we'll obtain the "extreme" signal? User setting, platform / OS signals, other means? I see a few options for how we can interpret them:
I was thinking that the browser would convey how much data savings is desired, not how expensive the data is. So if saveAsMuchDataAsPossible is true, saveData should also be true. I also think we should not all saveAsMuchDataAsPossible=true, saveData=false, because many sites will only have one data saving implementation. If that implementation isn't extreme, the site could just check saveData. If it is extreme, it could check saveAsMuchDataAsPossible.
We could instead attempt to surface how expensive the data is, but I'm afraid the best we can do now is to use heuristics or classified a user's historical data use, which would be extremely coarse.
Hmm ok. Sounds like we want saveData as a boolean then, not an enum, plus an additional property communicate the "severity"...? In theory, doesn't effectiveType hint at this already?
if (navigator.connection.saveData) {
if (navigator.connection.effectiveType == "slow-2g") {
// super duper compression
} else {
// ...
}
}
Translating above to headers, we might have:
Save-Data: on;slow-2g
Given that we already expose ECT, do we need any additional signals?
An effectiveType slower than 3g indicates a need for super duper compression, as does an actual connection type of 2g, but there are likely many other signals that could contribute to a need for it, e.g., a user setting. All that said, I think a boolean is fine for now and we can invent an additional property to communicate severity if we eventually need it.
@bengreenstein updated, ptal. @mnot per discussion earlier, also moving Save-Data definition into NetInfo -- ptal.
Thanks Mark! @bengreenstein @tarunban any feedback on your end?
lgtm
Thanks everyone for reviews and feedback, merging.
Attribute reflects value advertised by Save-Data header defined by Clients Hints specification.
Open questions to address:
As an aside, it may also make sense to migrate Save-Data definition into this spec, instead of defining it in CH; that way we can spell out the processing and interop between them more cleanly.
Closes https://github.com/WICG/netinfo/issues/42.
/cc @tarunban @jeffposnick @marcoscaceres @bengreenstein
Preview | Diff