0
<img src="http://assets.example.com/static/thumb_{{selected}}.jpg"/>

my selected model is dynamic, I can load the img proper but how to cache every single photo because I notice there's a delay when I apply new value to selected.

1
  • Is your asset store under your control? You could set correct cache-control headers to tell the browser to cache the resource. Commented Oct 27, 2016 at 12:41

2 Answers 2

1

angular .module('demo', [ 'ngImageCache' ]) ;

Note: Image is loaded using javascript, content is stored in sessionStorage for next loading

Use package npm install ng-image-cache

Sign up to request clarification or add additional context in comments.

3 Comments

Part of the requirements was 'without plugin'. This seems to contradict that requirement.
If you are not using through an $http service you might use the $cacheFactory service that generates cache objects for all Angular services. Internally, the $cacheFactory creates a default cache object.
use put method: cache.put(key, value); & you can easily access the key by cache.get(key); Or if you're using any $http method then $http({ method: 'GET', url: '/api/dummyimages.json', cache: true });
0

The easiest way would be to do it in your controller:

angular.module('app').controller('myController', function(images) {
    var preload = {};
    angular.forEach(images, function(image, i) {
        preload[i] = new Image()
        preload[i].src = "http://assets.example.com/static/thumb_" + image + ".jpg";
    });
});

1 Comment

ah great, I forgot there's things call new Image()!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.