manifest資源提取工具

因業務須要,寫了個manifest資源提取工具,該機制是將html文件做爲入口文件進行資源抓取。原理是先簡單掃html token,而後直接遍歷每一個tag token是否屬於須要的資源(css,js,img),獲取到css link的時候,再抓取裏的圖片文件,最後再合併成資源集合對象並建立manifest文件。css

 

安裝:html

$ npm install manifest-res

使用:git

var mr = require("manifest-res"); mr.build("http://www.cnblogs.com", "./cnblogs.appcache", function(data){ console.log(data); });

該例子成功後會在當前目錄下建立cnblogs.appcache文件。github

 

對象方法說明:npm

build(file, manifestFileName, callback);app

    參數:dom

        file參數能夠是本地html文件路徑,也能夠是http路徑;工具

        manifestFileName爲新生成的文件名;ui

        callback回調接收一個data(Array)參數,爲提取出來的資源列表;spa

 

項目地址:https://github.com/randomyang/manifest-res

相關文章
相關標籤/搜索