Zephlon Zephlon - 3 months ago 9
jQuery Question

speedtest.net api

I want to make a widget to display the user's most recent speed test results. Does speedtest.net have an api I could use? I tried making an ajax request to http://speedtest.net/csv.php?csv=1&ria=0&s=0 but got a cross domain error. I tried an iframe, but that just made it appear in downloads.

This is going to be in a Google Chrome extension so I can use the chrome api if necessary.

Answer

speedtest.net is run by Ookla and their Speed Test application. Unfortunately they don't provide any public APIs for speedtest.net which you could use.

Although I doubt either of these meet your needs, they do provide Speed Test Mini and a hosted reporting solution for their full Speed Test software package (which includes CSV exporting capabilities).

The reason you're unable to use AJAX is because Chrome will not allow JavaScript to perform cross-site requests unless the Access-Control-Allow-Origin response header is set in the response from speedtest.net to permit such a request.

In a Chrome extension, however, you can allow cross-origin requests by adding the URL to the permissions section of your manifest.json file. For example:

"permissions": [
  "http://*/"
],

You could then use a bit of jQuery to retrieve the CSV data as a string (see this answer):

$.get('http://speedtest.net/csv.php?csv=1&ria=0&s=0', function(data) {
    var csv = new String(data);
    // do stuff with csv
}, dataType='text');