1.0.2 • Published 1 year ago

retry-script v1.0.2

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

retry-script

retry-script插件是一款能够使我们的项目、在加载js静态资源失败的时候、进行重新尝试加载(或者换域名重新加载)

特色功能:

  • 使用简单、支持自定义配置
  • 支持cdn的方式引入

快速开始

引入script (注意: 一定要在项目的最顶部引入)

<script src="http://xxx.xxx.xxx/retry-script.js"></script>
<script>
new RetryScript([
    'http://local/1',
    'http://local/2',
    'http://local/3'
 ])
</script>

注意: 一定要在项目的最顶部引入

配置项

支持两种方式配置

  • 1、仅配置hosts时, 可以简化为

    new RetryScript([
        'http://local/1',
        'http://local/2',
        'http://local/3'
     ])
  • 2、当多个配置时,看下面示例

    new RetryScript({
        hosts: [
            'http://local/1',
            'http://local/2',
            'http://local/3'
        ],
        handler (config) {
            return config.join('http://www.xxx.cn', config.source)
        }
    })
名称类型默认值必传说明
hostsstring[]重试的host数组列表, 当js加载失败时、默认会依次从hosts数组中按照顺序取出对应的域名来尝试加载js
handlerfunction处理函数, 接收config对象, 返回值作为下次重试的src 地址; 如果返回值是字符串,则作为下次重试的src地址; 返回值如果是其他类型,则使用默认规则生成下次重试地址

config对象说明

名称类型说明
currentIndexnumber重试的hosts的index索引
sourcestring解析出来的资源名
oldSrcstring上一次加载失败的src路径
hostsstring[]传入的配置项hosts
joinfunction路径拼接函数、用法同nodepath模块的join方法

方法

方法名返回值示例描述
destorycaptcha.destory()销毁控件
1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago