JSFiddle - React, Tailwind, and code Playground

by Flávio Cysne Ferreira Gomes

HTML

<input type="button" name="readScript" value="Read script tags sizes" onclick="readScriptSizes()" />
<input type="button" name="readStyles" value="Read style/link tags sizes" onclick="readStyleSizes()" />
<br/>
<div id="console"></div>

JavaScript

var log = function(info) {
    $('#console').append(info + '<br/>');
};

var callback = function(data) {
    log('Data received. Length is ' + data.length);
};

var readScriptSizes = function() {
    $('script[type*=javascript]').each(function(index) {
        var scriptLength = (this.text) ? this.text.length : 0;
        if (scriptLength == 0) {
            var url = this.src;
            log('script ' + index + ' requested: ' + url);
            try {
                $.get(url, callback);
            } catch (e) {}
        } else {
            log('script ' + index + ' length is ' + scriptLength);
        }
    });
};

var readStyleSizes = function() {
    $('link,style').each(function(index) {
        var cssLength = (this.innerText) ? this.innerText.length : 0;
        if (cssLength == 0) {
            var url = this.href;
            log('style ' + index + ' requested: ' + url);
            try {
                $.get(url, callback);
            } catch (e) {}
        } else {
            log('style ' + index + ' length is ' + cssLength);
        }
    });
};