Restuta / rcn.io

:bicyclist: Making bike racing in USA "a better place" or "great again"
https://rcn.io
MIT License
44 stars 18 forks source link

Improve Embdes #310

Open Restuta opened 6 years ago

Restuta commented 6 years ago

Currently we use iframes for widgets. (e.g. https://rcn.io/widgets/upcoming-events). I frames are slow and clunky.

See how angel.co does that (no iframes)

<script data-startup="apination" 
  src="https://angel.co/javascripts/embed_jobs.js" 
  id="angellist_embed" async>
</script>
(function () {
  var element = document.getElementById('angellist_embed');
  var xmlhttp = new XMLHttpRequest();
  xmlhttp.onreadystatechange = function(){
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        var div = document.createElement('div');
        div.innerHTML = xmlhttp.responseText;
        element.parentNode.insertBefore(div, element);
    }
  }
  var startup_slug = element.getAttribute('data-startup');
  xmlhttp.open("GET", "https://angel.co/job_profiles/embed?startup="+startup_slug, true);
  xmlhttp.send();

})();
Restuta commented 6 years ago

Related article https://codeburst.io/building-react-widget-libraries-using-webpack-e0a140c16ce4