Skip to content

Instantly share code, notes, and snippets.

@hscstudio
Created April 10, 2018 04:23
Show Gist options
  • Save hscstudio/52760056e840cd1c8e84a13d3ad5492c to your computer and use it in GitHub Desktop.
Save hscstudio/52760056e840cd1c8e84a13d3ad5492c to your computer and use it in GitHub Desktop.
<html>
<head></head>
<body>
<script src="http://unpkg.com/axios/dist/axios.min.js"></script>
<script type="text/javascript">
var request = obj => {
return new Promise((resolve, reject) => {
var req = new XMLHttpRequest();
req.open('GET', url);
req.onload = function() {
if (req.status == 200) {
resolve(JSON.parse(req.response));
}
else {
reject(Error(req.statusText));
}
};
req.onerror = function() {
reject(Error("Network Error"));
};
req.send();
})
}
var url = "https://api.rss2json.com/v1/api.json?rss_url=https%3A%2F%2Fmedium.com%2Ffeed%2Fwwwid"
function test(){
console.time('axios')
axios.get(url)
.then(data => {
console.log(data.data.items)
console.timeEnd('axios')
})
console.time('fetch')
fetch(url)
.then(r => r.json())
.then(body => {
console.log(body.items)
console.timeEnd('fetch')
})
console.time('xmlhttp')
request({url: url})
.then(data => {
console.log(data.items)
console.timeEnd('xmlhttp')
})
}
</script>
<button onclick="test()">TEST</button>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment