{"id":31970673,"url":"https://github.com/winjs-dev/winjs-plugin-assets-retry","last_synced_at":"2026-03-06T10:05:44.060Z","repository":{"id":310922794,"uuid":"1041760291","full_name":"winjs-dev/winjs-plugin-assets-retry","owner":"winjs-dev","description":"A Winjs plugin for automatic retry of static resource loading failures, implemented based on the `assets-retry` library.","archived":false,"fork":false,"pushed_at":"2026-03-05T17:12:57.000Z","size":725,"stargazers_count":1,"open_issues_count":4,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-03-05T20:04:34.016Z","etag":null,"topics":["assets-retry","plugin","static-assets","winjs"],"latest_commit_sha":null,"homepage":"https://winjs-dev.github.io/winjs-docs/plugins/assetsretry","language":"TypeScript","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/winjs-dev.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-08-21T01:11:34.000Z","updated_at":"2025-12-15T05:44:56.000Z","dependencies_parsed_at":"2025-08-21T03:49:14.677Z","dependency_job_id":"1d604e43-fa89-45bc-97a6-935d278bff49","html_url":"https://github.com/winjs-dev/winjs-plugin-assets-retry","commit_stats":null,"previous_names":["winjs-dev/winjs-assets-retry"],"tags_count":1,"template":false,"template_full_name":"winjs-dev/winjs-plugin-template","purl":"pkg:github/winjs-dev/winjs-plugin-assets-retry","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/winjs-dev%2Fwinjs-plugin-assets-retry","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/winjs-dev%2Fwinjs-plugin-assets-retry/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/winjs-dev%2Fwinjs-plugin-assets-retry/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/winjs-dev%2Fwinjs-plugin-assets-retry/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/winjs-dev","download_url":"https://codeload.github.com/winjs-dev/winjs-plugin-assets-retry/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/winjs-dev%2Fwinjs-plugin-assets-retry/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30171657,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-06T07:56:45.623Z","status":"ssl_error","status_checked_at":"2026-03-06T07:55:55.621Z","response_time":250,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["assets-retry","plugin","static-assets","winjs"],"created_at":"2025-10-14T19:18:07.595Z","updated_at":"2026-03-06T10:05:44.013Z","avatar_url":"https://github.com/winjs-dev.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# winjs-plugin-assets-retry\n\n一个用于静态资源加载失败自动重试的 Winjs 插件，基于 [assets-retry](https://github.com/BetaSu/assets-retry) 库实现。\n\n\u003cp\u003e\n  \u003ca href=\"https://npmjs.com/package/@winner-fed/plugin-assets-retry\"\u003e\n   \u003cimg src=\"https://img.shields.io/npm/v/@winner-fed/plugin-assets-retry?style=flat-square\u0026colorA=564341\u0026colorB=EDED91\" alt=\"npm version\" /\u003e\n  \u003c/a\u003e\n  \u003cimg src=\"https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square\u0026colorA=564341\u0026colorB=EDED91\" alt=\"license\" /\u003e\n  \u003ca href=\"https://npmcharts.com/compare/@winner-fed/plugin-assets-retry?minimal=true\"\u003e\u003cimg src=\"https://img.shields.io/npm/dm/@winner-fed/plugin-assets-retry.svg?style=flat-square\u0026colorA=564341\u0026colorB=EDED91\" alt=\"downloads\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\n## 功能特性\n\n- 🔄 **自动重试**: 当 JS、CSS 等静态资源加载失败时自动重试\n- 🎯 **域名白名单**: 支持配置域名白名单，只对指定域名的资源进行重试\n- ⚙️ **可配置**: 支持自定义重试次数、重试逻辑和回调函数\n- 🚀 **开箱即用**: 零配置即可使用，提供合理的默认配置\n- 📊 **监控支持**: 提供成功/失败回调，便于监控和统计\n\n## 安装\n\n```bash\nnpm install @winner-fed/plugin-assets-retry assets-retry\n```\n\n## 使用方法\n\n### 1. 启用插件\n\n在 `.winrc.ts` 文件中添加插件：\n\n```typescript\nimport { defineConfig } from 'win';\n\nexport default defineConfig({\n  plugins: [require.resolve('@winner-fed/plugin-assets-retry')],\n  assetsRetry: {\n    // 配置选项\n  }\n});\n```\n\n### 2. 配置选项\n\n```typescript\nexport default defineConfig({\n  plugins: [require.resolve('@winner-fed/plugin-assets-retry')],\n  assetsRetry: {\n    // 域名白名单，只有在此列表中的资源才会重试\n    domain: [\n      'https://cdn.example.com',\n      'https://static.example.com'\n    ],\n    \n    // 最大重试次数，默认为 3\n    maxRetryCount: 3,\n    \n    // 自定义重试逻辑\n    onRetry: (currentUrl, originalUrl, retryCollector) =\u003e {\n      console.log('重试中:', currentUrl);\n      // 返回新的 URL 或 null\n      return currentUrl;\n    },\n    \n    // 资源加载成功回调\n    onSuccess: (currentUrl) =\u003e {\n      console.log('加载成功:', currentUrl);\n    },\n    \n    // 资源加载失败回调\n    onFail: (currentUrl) =\u003e {\n      console.log('加载失败:', currentUrl);\n    }\n  }\n});\n```\n\n## 配置项说明\n\n| 参数 | 类型 | 默认值 | 描述 |\n|------|------|--------|------|\n| `domain` | `string[]` | `[]` | 域名白名单，只有在此列表中的资源才会重试 |\n| `maxRetryCount` | `number` | `3` | 每个资源的最大重试次数 |\n| `onRetry` | `function` | - | 自定义重试逻辑的回调函数 |\n| `onSuccess` | `function` | - | 资源加载成功的回调函数 |\n| `onFail` | `function` | - | 资源加载失败的回调函数 |\n\n### 回调函数参数说明\n\n#### onRetry 函数\n\n```typescript\ntype RetryFunction = (\n  currentUrl: string,      // 当前尝试的 URL\n  originalUrl: string,     // 原始 URL\n  retryCollector: RetryStatistics | null  // 重试统计信息\n) =\u003e string | null\n```\n\n#### RetryStatistics 接口\n\n```typescript\ninterface RetryStatistics {\n  retryTimes: number;    // 已重试次数\n  succeeded: string[];   // 成功的 URL 列表\n  failed: string[];      // 失败的 URL 列表\n}\n```\n\n## 使用场景\n\n1. **CDN 容灾**: 当主 CDN 服务出现问题时，自动切换到备用 CDN\n2. **网络波动**: 在网络不稳定环境下提升资源加载成功率\n3. **用户体验**: 减少因资源加载失败导致的白屏或功能异常\n4. **监控统计**: 通过回调函数收集资源加载失败的统计数据\n\n## 高级用法\n\n### 多域名容灾\n\n```typescript\nexport default defineConfig({\n  assetsRetry: {\n    domain: ['https://cdn1.example.com', 'https://cdn2.example.com'],\n    onRetry: (currentUrl, originalUrl, retryCollector) =\u003e {\n      // 切换到备用域名\n      if (currentUrl.includes('cdn1.example.com')) {\n        return currentUrl.replace('cdn1.example.com', 'cdn2.example.com');\n      }\n      return currentUrl;\n    }\n  }\n});\n```\n\n### 结合监控系统\n\n```typescript\nexport default defineConfig({\n  assetsRetry: {\n    domain: ['https://cdn.example.com'],\n    onSuccess: (currentUrl) =\u003e {\n      // 发送成功日志到监控系统\n      monitor.success('assets-retry', { url: currentUrl });\n    },\n    onFail: (currentUrl) =\u003e {\n      // 发送失败日志到监控系统\n      monitor.error('assets-retry', { url: currentUrl });\n    }\n  }\n});\n```\n\n## 注意事项\n\n1. 本插件依赖 `assets-retry` 库，需要同时安装\n2. 只有在配置的域名白名单中的资源才会被重试\n3. CSS 中的背景图片目前不支持重试\n4. 重试逻辑在页面加载时自动注入，无需额外代码\n\n## 许可证\n\n[MIT](./LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwinjs-dev%2Fwinjs-plugin-assets-retry","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwinjs-dev%2Fwinjs-plugin-assets-retry","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwinjs-dev%2Fwinjs-plugin-assets-retry/lists"}