{"id":21356063,"url":"https://github.com/hezhengjie/kabuto","last_synced_at":"2025-03-16T05:41:17.719Z","repository":{"id":57259932,"uuid":"213320008","full_name":"hezhengjie/kabuto","owner":"hezhengjie","description":"基于quicklink的预加载工具","archived":false,"fork":false,"pushed_at":"2019-12-30T12:36:20.000Z","size":156,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-23T00:47:15.040Z","etag":null,"topics":["prefetch","quicklink"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hezhengjie.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-10-07T07:25:53.000Z","updated_at":"2019-12-30T12:36:22.000Z","dependencies_parsed_at":"2022-08-25T01:51:34.266Z","dependency_job_id":null,"html_url":"https://github.com/hezhengjie/kabuto","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hezhengjie%2Fkabuto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hezhengjie%2Fkabuto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hezhengjie%2Fkabuto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hezhengjie%2Fkabuto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hezhengjie","download_url":"https://codeload.github.com/hezhengjie/kabuto/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243830922,"owners_count":20354850,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["prefetch","quicklink"],"created_at":"2024-11-22T04:28:08.163Z","updated_at":"2025-03-16T05:41:17.701Z","avatar_url":"https://github.com/hezhengjie.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# kabuto  \n\n基于quicklink的预加载工具。  \n\n## Background\nquicklink是Google开源的预加载工具，可以在空闲时间预获取页面可视区域（以下简称视区）内的链接，加快后续加载速度。  \n但是在实际应用中quicklink还是有一定问题：  \n1.dom监听只能监听a链接下的href资源  \n2.对于快速滑动的列表，会出现即使没有再视窗停留也会预加载的情况，出现大量的无效预加载。   \n3.对于html文档来说，只能预加载主文档，主文档内的资源无法预加载，对于一些依赖于js渲染的页面来讲，预加载意义不大。  \n为了解决这些问题，在quicklink的基础上，封装了kabuto(假面骑士kabuto，可以clock up 加速)。\n\n特点：  \n1.增加data-kabuto-link声明，有data-kabuto-link的元素也会被监听。  \n2.增加曝光时间设置，只有在视窗内持续曝光的元素会被预加载  \n3.增加html页面的资源解析，同时预加载页面和页面静态资源（只限于同域页面）\n\n## Install\n```\nnpm install h-kabuto --save \nor \nyarn add h-kabuto\n\n```\n\n## Usage\n\n初始化后，Kabuto 将自动在闲时预获取视区内的链接 URL。\n\n```javascript \n\nimport Kabuto from 'h-kabuto'\n\nconst kabuto = new Kabuto({\n    origins:this.origins,\n    ignores:this.ignores,\n    timeout:this.timeout\n});\nkabuto.add('http://127.0.0.1:3000/demo/demo.html');\n```\n\n## API\nkabuto的option参数基本和quick类似,接受带有以下参数的 option 对象（可选）：\n* el：指定需要预获取的 DOM 元素视区,默认为document。\n* urls：预获取的静态 URL 数组（若此参数非空，则不会检测视区中 document 或 DOM 元素的链接）。\n* timeout：整型数，为 requestIdleCallback 设置超时。浏览器必须在此之前进行预获取（以毫秒为单位）， 默认取 2 秒。\n* origins: 静态字符串数组，包含允许进行预获取操作的 URL 主机名。默认为同域请求源，可阻止跨域请求。\n* ignores: RegExp（正则表达式），Function（函数）或者 Array（数组），用于进一步确定某 URL 是否可被预获取。会在匹配请求源之后执行。\n* observeTime:预获取的 DOM 元素视区曝光的时间，只有曝光时间大于的dom才去预获取,默认取 0.5 秒。\n* noquery: 是否预加载不同参数的同样链接，默认为true;\n\n详情可参看 https://github.com/GoogleChromeLabs/quicklink/blob/master/translations/zh-cn/README.md\n\n## Methods\n\nkabuto 新增了一些方法\n\n#### add(url)\n\u003e 新增预加载的url\n```\nkabuto.add('http://127.0.0.1:3000/demo/demo.html')\n```\n\n#### observe(el) \n\n\u003e 新增要监听的dom\n```\nkabuto.observe(document.body)\n\n```\n\n## Notice \n\n1.对于dom的监听，可以在元素上增加data-kabuto-link属性，有data-kabuto-link的元素也会被监听。  \n```\n\u003cdiv data-kabuto-url=\"https://fed.taobao.org/\"\u003e\u003c/div\u003e\n//当前dom曝光是，会尝试预加载https://fed.taobao.org/和页面内的资源\n    \n``` \n2.对于页面类型的资源，会尝试去解析页面内的静态资源，并预加载，不过由于浏览器限制，该功能仅限于同源页面。\n\n## ChangeLog\n*0.1.2*  \n1.页面增加图片链接预加载  \n\n*0.1.3*  \n1.增加noquery参数，不同参数的同链接，默认不再预加载  \n\n\n\n## License\n[MIT](https://github.com/hezhengjie/kabuto/blob/master/LICENSE) © hezhengjie\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhezhengjie%2Fkabuto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhezhengjie%2Fkabuto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhezhengjie%2Fkabuto/lists"}