3

I have home page it contains with list of 2 images i have given controller and Html code.every time home page images loading from backend i want to cache the image in local to avoid every time http request and weekly once or 10 days once i want to check from backend if backend image has changed that time i need to update this cache image . i have followed some example but i could not solve this because i am new to this technology some one help me out to move forward

.controller('TestCtrl', [
    '$scope', '$http', '$location', '$window', '$ionicLoading',
    function($scope, $http, $location, $window, $ionicLoading) {
	       
        $scope.find = function() {
	     $http.get('****').success(function(data, status, headers, config, response) {
                
                $scope.image1 = data[0].Images1;
                $scope.image2 = data[1].Images2;
                
            })
        }
           
    }
])
//console i am getting image1:http://res.cloudinary.com/dl34322/image/upload/q_58/v1437810617/store1.png image2:http://res.cloudinary.com/dl34322/image/upload/q_58/v1437810617/store2.png
<ion-view  title="Home" data-ng-controller="TestCtrl" data-ng-init="find()">	
<ion-content>

<div class="list card">
  <div class="item item-image">
     <img src="{{image1}}">
  </div>
</div>
<div class="list card">
  <div class="item item-image">
     <img src="{{image2}}" >
  </div>
</div>
</ion-content> 
</ion-view >	

3
  • Just use standard HTTP headers to cache static content Commented Aug 17, 2015 at 19:55
  • sorry i could't get u what ur trying to say Commented Aug 19, 2015 at 4:17
  • @reptilicus Can yo please be more specific? maybe show an example code? Commented Nov 12, 2015 at 20:31

2 Answers 2

3

Try using ng-src instead of src in <img> elements as shown below:

 <ion-view  title="Home" data-ng-controller="TestCtrl" data-ng-init="find()">   
    <ion-content>

    <div class="list card">
      <div class="item item-image">
         <img ng-src="{{image1}}">
      </div>
    </div>
    <div class="list card">
      <div class="item item-image">
         <img ng-src="{{image2}}" >
      </div>
    </div>
    </ion-content> 
    </ion-view >    
Sign up to request clarification or add additional context in comments.

1 Comment

Please call out what changes you've made to the code. It's hard to see at a glance that you've used ng-src.
1

You can use $ImageCacheFactory to cache images once and load it from cache when you need to load that again. Full documentation here

Comments

Your Answer

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