npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

retry-cdn

v0.1.2

Published

Automatically switch the domain name when error

Downloads

4

Readme

retry-cdn

说明

CDN资源报错时进行CDN域名自动切换,防止页面GG

使用

将retry-cdn置于所有资源之前,定义备用域名列表,创建RetryCDN对象

H5

   <script>
      const urlArr = [
        'https://cdnjs.cloudflare.com',
        'https://images.unsplash.com',
        'https://plus.unsplash.com',
      ]
      const retry = new RetryCDN(urlArr)
    </script>

webpack

main.js 中引入并实例化

安装

  npm install retry-cdn --save-dev
  import RetryCDN from 'retry-cdn';

  const urlArr = [
    'https://cdnjs.cloudflare.com',
    'https://images.unsplash.com',
    'https://plus.unsplash.com',
  ]
  new RetryCDN(urlArr)

vite

vite开发环境使用esbuild构建(只支持esm),需要另外引入安装@originjs/vite-plugin-commonjs

  npm install retry-cdn --save-dev
  npm install @originjs/vite-plugin-commonjs --save-dev

vite.config.js中进行如下配置

import { viteCommonjs } from '@originjs/vite-plugin-commonjs'

export default defineConfig(({ mode, command }) => {
  ...
    plugins: [
      viteCommonjs()
    ],
  ...
})

main.js 中引入并实例化

import RetryCDN from "retry-cdn";
  const urlArr = [
    'https://cdnjs.cloudflare.com',
    'https://images.unsplash.com',
    'https://plus.unsplash.com',
  ]
  new RetryCDN(urlArr)

背景图切换原理

在DOMContentLoaded之后先取出当前第一个背景链接查看是否有效,如无效则拼备用域名全部列表,然后取出能正常访问的域名再进行统一替换

限制

因无法监听到背景图的报错,所以默认全部的背景图必须用的是同一个域名。

优点

直接从域名列表中取出正确的域名进行统一替换,减少资源重试次数