Socket
Socket
Sign inDemoInstall

@moyu/bucket.js

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @moyu/bucket.js

cache scripts and styles in localStorage


Version published
Weekly downloads
4
Maintainers
1
Created
Weekly downloads
 

Readme

Source
bucket.js

移动端LocalStorage缓存资源方案

安装

npm install @moyu/bucket.js

使用

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()

Keywords

FAQs

Last updated on 27 Dec 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc