jquery-ajax-localstorage-cache Bower npm

Ajax Cache backed by localStorage for jQuery

3 years after


jquery-ajax-localstorage-cache - abbreviated Jalc from here on, because the full name is a mouthful.

Jalc is a plugin built for jQuery (> 1.5.1) and any object implementing the storage interface, such as localStorage.

It's built on a fork from the jStorage-dependent original. It provides a client-side cache for AJAX responses intended to save bandwith and time.

Looking for a version that supports binary data (Blobs, ArrayBuffers)? Check out Jalic.

Looking for a version that offers caching for the new Fetch API? Check out fetchCache.



        url          : '/post',
        localCache   : true,        // Required. Either a boolean, in which case localStorage will be used, or
        an object that implements the Storage interface.

        cacheTTL     : 1,           // Optional. In hours.
        cacheKey     : 'post',      // optional.
        isCacheValid : function(){  // optional.
            return true;
        // The response is available here.

On your AJAX request you get 4 new parameters :

  • localCache
    • Turn localCache on/off, or specify an object implementing the Storage interface to use.
    • Default: false
  • cacheTTL
    • time in hours the entry should be valid.
    • only for this specific ajax request
    • Default : 5 hours
  • cacheKey
    • CacheKey is the key that will be used to store the response in localStorage. It allow you to delete your cache easily with the localStorage.removeItem() function.
    • A callback function can also be used to return dynamically generated cacheKey. ajax options are passed to this callback, but keep in mind that the function needs to return a stable cacheKey - that is, for a given set of parameters, the function should always return the same generated cacheKey.
    • Default: URL + TYPE(GET/POST) + DATA
  • isCacheValid
    • This function must return true or false. On false, the cached response is removed.
    • Default: null


  • You can delete the cache by using localStorage.clear(), or by using localStorage.removeItem('cacheKey') if you specified a cacheKey. Note the above assumes you're using localStorage - replace as appropriate with your Storage interface implementing object.
  • You can pre-load content with this plugin. You just have do to an initial AJAX request with the same cacheKey.
  • In most cases, you can rely on the 'intelligent guess' for the dataType jQuery ajax parameter, and leave off the dataType parameter, and the plugin will store the content type returned from the server alongside the data. However, you will get more consistent results if you explicitly specify the dataType in the ajax parameters.


This project is distributed under Apache 2 License. See LICENSE.txt for more information.

Related Repositories



A jQuery plugin to facilitate conveniently working with local storage ...



Caching for Backbone's fetch method ...



JavaScript SDK design guide extracted from work and personal experience ...



An extension to Backbone providing localStorage caching for Backbone sync operat ...



Simple, secure token authentication for jQuery. ...

Top Contributors

SaneMethod paulirish caleywoods iRyusa softwarespot basicallydan robink shaqq bshelton229 dguzzo huntzhan mludv NigelKibodeaux sunnokon tronhammer


-   1.0.2 zip tar
-   1.0.1 zip tar
-   1.0.0 zip tar