通过几个ajax请求测量javascript中的带宽消耗

I'm trying to measure bandwidth consumption in JavaScript for my Ajax requests/responds. I'm requesting data from the server using Ajax asynchronously, where I'm sending data for let's say every second by polling the server. I've already counted the header data that will be sent over the network. So in this example, let us skip the header data thing.

I would like to measure the bandwidth consumption live by adding code to this:

setInterval(function(){
  $.ajax({
    type: "POST",
    url: "msgsrv.php",
    data: {
      size: 500bytesOfData
    },
    async: true,

    success: function(data){
      console.log(data); 
      //data sent back from server (for example: data=500)
    },

    error: function(XMLHttpRequest, textStatus, errorThrown){
      alert("error" + textStatus + " (" + errorThrown + ")");
    }
  )};
}, 1000);

If your interested in fetching exact network metrics from your web application I highly recommend: Charles Proxy

It has a limited free trial period, and is worth every penny of the $50 license fee.