Registry / storage / backbone-fetch-cache

backbone-fetch-cache

JSON →
library2.0.1jsnpmunverified

A plugin for Backbone.js that caches results of Model.fetch and Collection.fetch calls in memory and localStorage. Version 2.0.1, updated as a stable release. It intercepts fetch calls and serves cached responses when options.cache is true, with configurable expiration. Key differentiator: provides 'prefill' option to populate models/collections from cache immediately then update via AJAX, improving perceived performance. Supports AMD and CommonJS. Requires Backbone >=1.0.0 and jQuery (or compatible Deferred implementation).

npm install backbone-fetch-cache
INSTALL
IMPORT
SIG · BACKBONE-FETCH-CAC
B
backbone-fetch-cache
storagejavascriptv2.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

fetchCache
var fetchCache = require('backbone-fetch-cache');
import fetchCache from 'backbone-fetch-cache';
CommonJS only; package does not export an ES module. Use require() in Node or bundler context.
Backbone.fetchCache
require('backbone-fetch-cache'); // Then use Backbone.fetchCache.*
var Backbone = require('backbone'); var fetchCache = require('backbone-fetch-cache'); fetchCache.enable();
Plugin attaches itself to Backbone object; just require it to load.
AMD module
require(['path/to/backbone.fetch-cache.js']);
define(['backbone.fetch-cache'], function(fc) { ... });
AMD usage does not return a module; it modifies Backbone in-place. Just require it.

Shows how to install, require the plugin, and use cache option on fetch.

// Install: npm install backbone-fetch-cache var Backbone = require('backbone'); require('backbone-fetch-cache'); // activates the plugin var MyModel = Backbone.Model.extend({ url: '/api/item' }); var model = new MyModel(); // Fetch with cache enabled model.fetch({ cache: true, expires: 30000, // 30 seconds success: function() { console.log('Data:', model.toJSON()); } }); // Second call will serve from cache model.fetch({ cache: true });
Debug
Known issues
gotchaPlugin is CommonJS-only; no ESM export. Cannot use import in ES module projects.
fix
Use require() or dynamic import with default interop.
affects: *
gotchaCaching is based on URL and fetch options; if URL does not change, cached response is served regardless of server-side changes.
fix
Clear cache manually with Backbone.fetchCache.clearItem(url) or set expires to a reasonable value.
affects: *
gotchalocalStorage persistence requires same-origin and non-private browsing; may throw in Safari private mode.
fix
Wrap usage in try-catch or disable localStorage via Backbone.fetchCache.localCache = false.
affects: *
deprecatedOptions like 'prefillExpires' are deprecated; use 'expires' along with 'prefill'.
fix
Replace prefillExpires with expires: <seconds> in the fetch options.
affects: >=2.0.0
gotchaZepto.js lacks jQuery.Deferred; must include a standalone Deferred library.
fix
Include a library like Standalone-Deferred before loading backbone-fetch-cache.
affects: *
Errors
Common errors & fixes
Uncaught TypeError: Cannot read properties of undefined (reading 'Deferred')
Plugin expects jQuery.Deferred but jQuery is not loaded or Zepto is used without Deferred polyfill.
fix
Ensure jQuery is loaded before the plugin. If using Zepto, include a Deferred implementation.
Module not found: Error: Can't resolve 'backbone-fetch-cache'
Package not installed or incorrect import path in bundler.
fix
Run 'npm install backbone-fetch-cache' and check that require path is correct.
Backbone.fetchCache is not a function
Plugin not required or imported before usage.
fix
Add 'require("backbone-fetch-cache")' after Backbone is loaded.
Upgrade
Version history
2.0.1latest on npm
Audit
Dependencies
backbonerequiredPeer dependency; plugin modifies Backbone's fetch
jqueryoptionalUses jQuery.Deferred for promise handling
Agent activity
55 hits · last 30 days
node
46
Resources
backbone-fetch-cache — npm install backbone-fetch-cache · libregistry