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 🙏

© 2026 – Pkg Stats / Ryan Hefner

solid-media

v1.0.1

Published

A framework-agnostic Web Component for controlled image and video loading with auth, dedup, concurrency, retry, and LRU cache.

Readme

solid-media

A framework-agnostic Web Component for controlled image and video loading.
Handles authenticated requests, request deduplication, concurrency control, exponential backoff retry, LRU memory management, and SSR safety.


Features

  • Authenticated fetch via custom fetcher injection
  • Global concurrency limit (default: 8 concurrent requests)
  • In-flight request deduplication
  • Exponential backoff retry (3 attempts: 1s / 2s / 4s), skips 4xx errors
  • LRU cache with reference counting and URL.revokeObjectURL (default: 50 entries)
  • Lazy loading via IntersectionObserver
  • Auto-infers image / video type from URL extension
  • SSR-safe (guards all browser APIs with typeof window)
  • Zero runtime dependencies
  • TypeScript strict mode, full type exports

Installation

bun add solid-media

Usage

Register the component

The component self-registers when imported in a browser environment:

import 'solid-media'

Basic

<solid-media src="/images/photo.jpg"></solid-media>
<solid-media src="/videos/clip.mp4" controls muted autoplay loop></solid-media>

With fallback placeholder

<solid-media src="/images/photo.jpg" fallback="/images/placeholder.jpg"></solid-media>

Force type

<solid-media src="/api/asset/42" type="video" controls></solid-media>

API

core.setFetcher(fn)

Inject a custom fetcher for authenticated or proxied requests.

import { core } from 'solid-media'

core.setFetcher(async (url) => {
  const res = await fetch(url, {
    headers: { Authorization: `Bearer ${token}` },
  })
  if (!res.ok) throw new Error(`HTTP ${res.status}`)
  return res.blob()
})

core.on(event, handler)

Subscribe to lifecycle events.

| Event | Description | | ----------- | ---------------------------------- | | success | Resource loaded successfully | | error | All retries exhausted | | retry | A retry attempt was triggered | | cache_hit | Resource served from cache |

core.on('retry', ({ url, attempt }) => {
  console.warn(`Retrying ${url}, attempt ${attempt}`)
})

Attributes

| Attribute | Type | Default | Description | | ------------ | ------------------ | --------- | ------------------------------------------------ | | src | string | — | Resource URL | | type | image | video | auto | Force media type; inferred from extension if omitted | | fallback | string | — | URL shown during loading and on error | | autoplay | boolean attr | — | Video only | | loop | boolean attr | — | Video only | | muted | boolean attr | — | Video only | | controls | boolean attr | — | Video only | | playsinline| boolean attr | — | Video only |


Build

bun run build

Output is placed in dist/ as ESM (.js), CJS (.cjs), and TypeScript declarations (.d.ts / .d.cts).


License

MIT


solid-media (中文)

框架无关的 Web Component,用于受控的图片和视频加载。
解决鉴权请求、请求去重、并发控制、指数退避重试、LRU 内存回收以及 SSR 安全问题。


特性

  • 通过自定义 fetcher 注入实现鉴权请求
  • 全局并发限制(默认最大 8 个并发请求)
  • 同一 URL 的请求自动去重
  • 指数退避自动重试(3 次,延迟分别为 1s / 2s / 4s),跳过 4xx 错误
  • 带引用计数的 LRU 缓存,自动调用 URL.revokeObjectURL 释放内存(默认上限 50 条)
  • 基于 IntersectionObserver 的懒加载
  • 根据 URL 后缀自动推断 image / video 类型
  • SSR 安全(所有浏览器 API 均做 typeof window 守卫)
  • 零运行时依赖
  • TypeScript 严格模式,完整类型导出

安装

bun add solid-media

使用

注册组件

在浏览器环境中导入后,组件会自动注册:

import 'solid-media'

基础用法

<solid-media src="/images/photo.jpg"></solid-media>
<solid-media src="/videos/clip.mp4" controls muted autoplay loop></solid-media>

带占位图

<solid-media src="/images/photo.jpg" fallback="/images/placeholder.jpg"></solid-media>

强制指定类型

<solid-media src="/api/asset/42" type="video" controls></solid-media>

API

core.setFetcher(fn)

注入自定义 fetcher,用于鉴权或代理请求。

import { core } from 'solid-media'

core.setFetcher(async (url) => {
  const res = await fetch(url, {
    headers: { Authorization: `Bearer ${token}` },
  })
  if (!res.ok) throw new Error(`HTTP ${res.status}`)
  return res.blob()
})

core.on(event, handler)

订阅生命周期事件。

| 事件 | 说明 | | ----------- | ------------------------ | | success | 资源加载成功 | | error | 全部重试耗尽后仍失败 | | retry | 触发了一次重试 | | cache_hit | 资源命中缓存 |

core.on('retry', ({ url, attempt }) => {
  console.warn(`正在重试 ${url},第 ${attempt} 次`)
})

属性

| 属性 | 类型 | 默认值 | 说明 | | ------------ | ------------------ | ------ | --------------------------------------------- | | src | string | — | 资源 URL | | type | image | video | 自动 | 强制指定媒体类型;未提供时根据后缀自动推断 | | fallback | string | — | 加载中及加载失败时显示的占位图 URL | | autoplay | 布尔属性 | — | 仅视频 | | loop | 布尔属性 | — | 仅视频 | | muted | 布尔属性 | — | 仅视频 | | controls | 布尔属性 | — | 仅视频 | | playsinline| 布尔属性 | — | 仅视频 |


构建

bun run build

产物输出至 dist/,包含 ESM(.js)、CJS(.cjs)及 TypeScript 声明文件(.d.ts / .d.cts)。


许可证

MIT

bun run index.ts

This project was created using bun init in bun v1.3.4. Bun is a fast all-in-one JavaScript runtime.