# @moyu/bucket.js

> cache scripts and styles in localStorage

Latest version **0.0.2** (published 2018-12-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install @moyu/bucket.js
pnpm add @moyu/bucket.js
yarn add @moyu/bucket.js
bun add @moyu/bucket.js
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2018-12-27 |
| First published | 2018-12-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 11.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 15 |
| Author | moyus |
| Maintainers | moyu |
| Keywords | localStorage, cache, script, style |

## Links

- npm: https://www.npmjs.com/package/@moyu/bucket.js
- Repository: https://github.com/moyus/bucket.js
- Homepage: https://github.com/moyus/bucket.js#readme
- Issues: https://github.com/moyus/bucket.js/issues
- npm.io page: https://npm.io/package/@moyu/bucket.js

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 0.0.2 (latest) — 2018-12-27
- 0.0.1 — 2018-12-27

## README

<div align="center">
  <img width="160" height="50" src="logo.svg" alt="bucket.js" />
  <p>移动端LocalStorage缓存资源方案</p>
</div>

## 安装
```bash
npm install @moyu/bucket.js
```

## 使用
```javascript
bucket.timeout = 10000; // 请求超时10s
bucket.prefix = 'bucket-'; // localStorage前缀
bucket.expire = 24 * 7; // 7天的缓存时间
bucket.require([
  {
    url: 'https://www.xxx.xxx/static/styles.123.css',
    key: 'styles',
    unique: '123',
    cache: true
  },
  {
    url: 'https://www.xxx.xxx/static/vendors.456.js',
    key: 'vendors',
    unique: '456',
    cache: true
  },
  {
    url: 'https://www.xxx.xxx/static/app.789.js',
    key: 'app',
    unique: '789',
    cache: true
  }
], function (resources) {
  // 所有资源均已加载并按顺序插入到了head中
});

// 获取本地缓存资源
bucket.get('app');
// {
//   content: string   // 资源内容
//   type: string      // 资源类型
//   stamp: number     // 什么时候缓存的
//   unique: string    // hash值
//   expire: number    // 多久之后过期
// }

// 删除本地缓存资源
bucket.remove('vendors')

// 清空本地所有缓存资源
bucket.clear()
```

---
_Source: https://npm.io/package/@moyu/bucket.js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
