Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of navigator.connection.saveData?

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.

like image 298
Bhautik Chudasama Avatar asked Apr 15 '18 06:04

Bhautik Chudasama


2 Answers

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.com), navigator.connection API is currently only supported in Chrome versions 61+. It will not work with other browsers yet.

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

like image 125
Nisarg Shah Avatar answered Sep 20 '22 17:09

Nisarg Shah


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);
like image 24
Piotr Mirosz Avatar answered Sep 23 '22 17:09

Piotr Mirosz