admin管理员组

文章数量:1296920

I see the w3c site in navigator.connection.saveData object but I didn't understand what is the use? and where can I use it on my website?

Please anyone can explain me about this.

I see the w3c site in navigator.connection.saveData object but I didn't understand what is the use? and where can I use it on my website?

Please anyone can explain me about this.

Share Improve this question edited Apr 15, 2018 at 6:13 Nisarg Shah 14.6k6 gold badges38 silver badges57 bronze badges asked Apr 15, 2018 at 6:01 Bhautik ChudasamaBhautik Chudasama 7129 silver badges28 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 8

According to the Network Information API spec, it looks like saveData attribute indicates whether the user has requested that data usage be reduced by the user agent:

The saveData attribute, when getting, returns true if the user has requested a reduced data usage mode from the user agent, and false otherwise.

NOTE

The user may enable such preference, if made available by the user agent, due to high data transfer costs, slow connection speeds, or other reasons.


Regarding your second question,

Where can I use it on my website?

According to MDN (and CanIUse.), navigator.connection API is currently only supported in Chrome versions 61+. It will not work with other browsers yet.

In fact, according to CanIUse., Chrome only supports the downlink, effectiveType & rtt attributes on navigator.connection. So you might not be able to use saveData on Chrome either.

so. navigator.connection.saveData saving data about user connection. Definition of Navigator Connection

The Network Information API provides information about the system's connection in terms of general connection type (e.g., 'wifi', 'cellular', etc.). This can be used to select high definition content or low definition content based on the user's connection. The entire API consists of the addition of the NetworkInformation interface and a single property to the Navigator interface: Navigator.connection.

Example code:

var connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection;
var type = connection.type;

function updateConnectionStatus() {
  console.log("Connection type changed from " + type + " to " + connection.type);
}

connection.addEventListener('change', updateConnectionStatus);

本文标签: javascriptWhat is the purpose of navigatorconnectionsaveDataStack Overflow