統計代碼字數

引用 http://www.phpied.com/quick-stats-on-html-js-css-sizes/

如果你想統計文件中html,css,javascript的數量可以用下面的代碼。

// 統計文件中代碼的數量
const total = document.documentElement.innerHTML.length;
const scripts = Array.from(document.getElementsByTagName('script')).reduce((total, e) => total += e.innerHTML.length, 0);
const styles = Array.from(document.getElementsByTagName('style')).reduce((total, e) => total += e.innerHTML.length, 0);
console.log("scripts", scripts, "styles:", styles, "html:", total - scripts - styles);

結果
這裏寫圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章