Code Monkey home page Code Monkey logo

mobot's Introduction

mobot.js

移动端LocalStorage缓存资源方案

安装

npm install mobot

使用

mobot.timeout = 10000; // 请求超时10s
mobot.prefix = 'mobot-'; // LocalStorage前缀
mobot.expire = 24 * 7; // 7天的缓存时间
mobot.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 (err, resources) {
  // 所有资源均已加载并按顺序插入到了head中
});

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

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

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

相关讨论

https://www.zhihu.com/question/28467444

mobot's People

Contributors

moyus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.