{"id":13827741,"url":"https://github.com/jin5354/prefetch-polyfill-webpack-plugin","last_synced_at":"2025-04-13T13:41:37.442Z","repository":{"id":57329716,"uuid":"104450263","full_name":"jin5354/prefetch-polyfill-webpack-plugin","owner":"jin5354","description":"Prefetch polyfill plugin for webpack async chunks to imporve load time (on safari)","archived":false,"fork":false,"pushed_at":"2017-10-09T07:49:58.000Z","size":79,"stargazers_count":46,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-27T04:41:34.687Z","etag":null,"topics":[],"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/jin5354.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":"2017-09-22T08:23:39.000Z","updated_at":"2023-08-15T16:18:21.000Z","dependencies_parsed_at":"2022-09-16T17:52:16.157Z","dependency_job_id":null,"html_url":"https://github.com/jin5354/prefetch-polyfill-webpack-plugin","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jin5354%2Fprefetch-polyfill-webpack-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jin5354%2Fprefetch-polyfill-webpack-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jin5354%2Fprefetch-polyfill-webpack-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jin5354%2Fprefetch-polyfill-webpack-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jin5354","download_url":"https://codeload.github.com/jin5354/prefetch-polyfill-webpack-plugin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248724342,"owners_count":21151557,"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":[],"created_at":"2024-08-04T09:02:06.686Z","updated_at":"2025-04-13T13:41:37.420Z","avatar_url":"https://github.com/jin5354.png","language":"JavaScript","readme":"# prefetch-polyfill-webpack-plugin\n\n[![Build Status](https://travis-ci.org/jin5354/prefetch-polyfill-webpack-plugin.svg?branch=master)](https://travis-ci.org/jin5354/prefetch-polyfill-webpack-plugin)\n[![Coverage Status](https://coveralls.io/repos/github/jin5354/prefetch-polyfill-webpack-plugin/badge.svg?branch=master)](https://coveralls.io/github/jin5354/prefetch-polyfill-webpack-plugin?branch=master)\n[![npm package](https://img.shields.io/npm/v/prefetch-polyfill-webpack-plugin.svg)](https://www.npmjs.org/package/prefetch-polyfill-webpack-plugin)\n[![npm downloads](https://img.shields.io/npm/dt/prefetch-polyfill-webpack-plugin.svg)](https://www.npmjs.org/package/prefetch-polyfill-webpack-plugin)\n[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)\n\n## Intro\n\nThis plugin automatically wire up your async thunks with a prefetch polyfill function(using new Image().src or `\u003cscript async\u003e`) for platform which doesn't support `\u003clink rel='prefetch'\u003e`, such as safari, to improve load time.\n\nThis is an extension plugin for [html-webpack-plugin](https://github.com/jantimon/html-webpack-plugin).\n\nThe prefetch polyfill function will be injected before `\u003c/body\u003e`.\n\n```html\n\u003c!-- as default it use new Image().src --\u003e\n\u003cscript\u003e\n  (function(){\n    var ua = (typeof navigator !== 'undefined' ? navigator.userAgent || '' : '')\n    if(/safari|iphone|ipad|ipod|msie|trident/i.test(ua) \u0026\u0026 !/chrome|crios|crmo|firefox|iceweasel|fxios|edge/i.test(ua)) {\n      window.onload = function () {\n        var i = 0, length = 0,\n          preloadJs = ['/chunk.a839f9eac501a92482ca.js', ...your thunks]\n\n        for (i = 0, length = preloadJs.length; i \u003c length; i++) {\n          new Image().src = preloadJs[i]\n        }\n      }\n    }\n  })()\n\u003c/script\u003e\n\n\u003c!-- you can choose to use \u003cscript async\u003e --\u003e\n\u003cscript\u003e\n(function(){\n  var ua = (typeof navigator !== 'undefined' ? navigator.userAgent || '' : '')\n  if(/safari|iphone|ipad|ipod|msie|trident/i.test(ua) \u0026\u0026 !/chrome|crios|crmo|firefox|iceweasel|fxios|edge/i.test(ua)) {\n    window.onload = function () {\n      var i = 0, length = 0, js,\n        preloadJs = ['/chunk.a839f9eac501a92482ca.js', ...your thunks]\n\n      for (i = 0, length = preloadJs.length; i \u003c length; i++) {\n        js = document.createElement('script')\n        js.src = preloadJs[i]\n        js.async = true\n        document.body.appendChild(js)\n      }\n    }\n  }\n})()\n\u003c/script\u003e\n```\n\n![example](https://user-images.githubusercontent.com/6868950/30850447-30b6856a-a26b-11e7-812a-9e85e9e4aebe.jpeg)\n\n## Install\n\n```bash\nnpm install prefetch-polyfill-webpack-plugin --save-dev\n```\n\n## Usage\n\nIn webpack config, require the plugin:\n\n```javascript\nconst PrefetchPolyfillPlugin = require('prefetch-polyfill-webpack-plugin');\n```\n\nand add this plugin after HtmlWebpackPlugin:\n\n```javascript\nplugins: [\n  new HtmlWebpackPlugin(),\n  new PrefetchPolyfillPlugin()\n]\n```\n\nThis plugin works well with [preload-webpack-plugin](https://github.com/GoogleChrome/preload-webpack-plugin). If you are using code splitting you are recommended to use both plugin at the same time.\n\n## options\n\n### mode\n\nSet mode to `async` to use `\u003cscript async\u003e` to prefetch, or use `new Image().src` as default.\n\n```javascript\nplugins: [\n  new HtmlWebpackPlugin(),\n  new PrefetchPolyfillPlugin({\n    mode: 'async'\n  })\n]\n```\n\n## Acknowledgment\n\n[preload-webpack-plugin](https://github.com/GoogleChrome/preload-webpack-plugin)\n\n## LICENSE\n\nMIT\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjin5354%2Fprefetch-polyfill-webpack-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjin5354%2Fprefetch-polyfill-webpack-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjin5354%2Fprefetch-polyfill-webpack-plugin/lists"}