Ask DN: Show me your website!

over 7 years ago from Enakshi Roy, Compile Inc.

  • A. M. ­DouglasA. M. ­Douglas, over 7 years ago (edited over 7 years ago )

    Yes, I cheat and use JSONP. I pull the Github API endpoint down (async'd) and the callback fires a function declared prior, which receives the data, builds the repo elements and adds them to a container at once.

    <div id="github"></div> <script> function loadrepos(results){ "use strict"; if ( > 0 ) { for ( var i =; i-- ) { var repo_url =[i].homepage ?[i].homepage :[i].html_url, repo_name =[i].name, repo_desc =[i].description, repo_lang =[i].language, repo_container = document.getElementById("github"), el = document.createElement("div"), // each repo will be in one of these el_link = document.createElement("a"), // a link will wrap the title, description and language el_title = document.createElement("h4"), // title el_desc = document.createElement("p"), // description el_lang = document.createElement("p"); // language el_link.href = repo_url; el_link.title = repo_name; el_title.textContent = repo_name; // use textContent because it's faster than .innerHTML el_desc.textContent = repo_desc; el_lang.textContent = repo_lang; el_link.appendChild(el_title); el_link.appendChild(el_desc); el_link.appendChild(el_lang); el.appendChild(el_link); repo_container.appendChild(el); } } else { console.log('Github is down'); } } </script> <script async defer src=""></script>


    JSONP is technically more efficient and it's easier to work with!

    0 points