Giacomo Balli profile picture
Giacomo Balli
Complex decisions. Clear thinking.

Independent advice for business owners navigating technology decisions, challenges and opportunities.
Fluent in business. Grounded in technology. Paid only by you.

Let’s Talk It Through LinkedIn

Building technology products since 2010 · 100+ apps

Get API or File Size

This code sample will allow you to retrieve the size of a file or API response without actually downloading it (server needs to provide Content-Length header).

function getApiSize(url) {
    var req = new XMLHttpRequest();
    req.open("HEAD", url, false);
    req.send(null);
    console.log(req.getResponseHeader('Content-Length'));
}

Directions:
- Call getApiSize(url); and you will see the size in your console.

Note:
This snippet focuses on iOS development. Make sure to verify/adapt any vendor prefixes. Back to main listing.

Published: Sun, Jan 10 2016 @ 18:48:03
Back to Blog