manifest资源提取工具

因业务需要,写了个manifest资源提取工具,该机制是将html文件作为入口文件进行资源抓取。原理是先简单扫html token,然后直接遍历每个tag token是否属于需要的资源(css,js,img),获取到css link的时候,再抓取里的图片文件,最后再合并成资源集合对象并创建manifest文件。

 

安装:

$ npm install manifest-res

使用:

var mr = require("manifest-res");

mr.build("http://www.cnblogs.com", "./cnblogs.appcache", function(data){
    console.log(data);
});

该例子成功后会在当前目录下创建cnblogs.appcache文件。

 

对象方法说明:

build(file, manifestFileName, callback);

    参数:

        file参数可以是本地html文件路径,也可以是http路径;

        manifestFileName为新生成的文件名;

        callback回调接收一个data(Array)参数,为提取出来的资源列表;

 

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

 

 

posted @ 2014-03-26 17:18  随机  阅读(1384)  评论(1编辑  收藏  举报