JS文件加載優化 ControlJS
ControlJS 主要為了是解決網頁加載中Js文件的性能問題,ControlJS的原理
ControlJS本身是異步進行加載的,首先將script的標簽type屬性值更改為瀏覽器無法識別的類型,這樣瀏覽器不會認為這是一個腳本。 本身異 步加載的ControlJS執行時開始遍歷type=”text/cjs”的script標簽(包括內嵌腳本),如果存在”DATA-CJSSRC”屬性 將創建IMAGE或者OBJECT對象(依賴瀏覽器而選擇),去異步預下載腳本文件并緩存文件,直到window.onload時解析并執行 javascript,同時第二次去遍歷遺漏的script標簽。
- downloads scripts asynchronously
- handles both inline scripts and external scripts
- delays script execution until after the page has rendered
- allows for scripts to be downloaded and not executed
- integrates with simple changes to HTML . no code changes
- solves some document.write async use cases
- control.js itself is loaded asynchronously
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!