JSFiddle - React, Tailwind, and code Playground

by ZenMaster

HTML

<div id="test"></div>
<div id="another"></div>
<div id="yetanother"></div>

JavaScript

var lazyLoad = {

    url: '',
    block: '',
    buffer: '',


    init: function(url, block) {
        this.url = url;
        this.block = block;
        console.log(this.block, block);
        window.d = document;
        window.buffer = '';
        d.write = d.writeln = function(s) {
            window.buffer += s;
        };
        d.open = d.close = function() {};
        this.addJS();
    },

    addJS: function() {
        that = this;
        s = d.createElement('script');
        s.setAttribute('type', 'text/javascript');
        s.setAttribute('src', this.url);
        d.getElementById(that.block).appendChild(s);
        s.onload = function() {
            that.pushHTML();
        };
    },

    pushHTML: function() {
        that = this;
        window.setTimeout(function() {
            d.getElementById(that.block).innerHTML += window.buffer;
            window.buffer = '';
        }, 0);
    }
};

lazyLoad.init('/echo/json/', 'test');
lazyLoad.init('/echo/json/', 'another');
lazyLoad.init('/echo/json/', 'yetanother');