GithubHelp home page GithubHelp logo

malaiappan / jqueryimagecaching Goto Github PK

View Code? Open in Web Editor NEW

This project forked from moledet/jqueryimagecaching

0.0 2.0 0.0 152 KB

jQuery plugin of image caching in localStorage

License: Apache License 2.0

JavaScript 100.00%

jqueryimagecaching's Introduction

jQueryImageCaching

jQuery plugin of image caching in localStorage

NOTICE: The most of browsers memory limit of localStorage is 5MB.

NOTICE: Correct way of image caching is using response of http server cache headers.

Version

1.0.0

Requirements

How to use

Simple way

<img data-src="path/to/image.(png,jpeg..)">

<script>
    $('img').imageCaching();
</script>

May use renderCallback and attach on several images.

<div class="user-img not-exist" data-src="path/to/image" data-caching-key="userImage"></div>

<script>
     $('.user-img').imageCaching({
         crossOrigin:null, //need if using cookie or session for render of image
         renderCallback:function(img,div){
                    $(div).removeClass('not-exist').css('background-image', 'url(' + img + ')');
         }});
</script>

By default all images save with key name as his url, if you need custom key name - use attribute 'data-caching-key'.

For refresh image better save of cachingObject.

<img data-src="path/to/image">

<script>
  var cachingObject = $('img').imageCaching();
  
  $('button').on('click',function(){
        cachingObject.refresh();
  });
</script>

If you will be delete image from localStorage.removeItem("path/to/image|or key") - new image will be loaded on refresh page.

More options

debugMode - default false, flag that give some console.log messages of working plugin for debug.

sourceKeyAttribute - default 'data-src', may change it on initialization

cachingKeyAttribute - default 'data-caching-key', may change it on initialization

renderCallback - default null, the callback after render image(change the selected item src). Arguments the image and html object where was changed attribute src.

crossOrigin - default 'Anonymous', origin of image in default mode not been send cookie or session id to server. Default mode may do problems for images that need authorization. This parameter change on problems with server headers. In most cases set this params to "null" will be remove problems.

jqueryimagecaching's People

Contributors

moledet avatar

Watchers

James Cloos avatar Malaiappan Kannan 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.