Skip to content

Commit

Permalink
No requests to the server
Browse files Browse the repository at this point in the history
  • Loading branch information
Glavan Dumitru committed Mar 8, 2011
1 parent 830109c commit 812c5e9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion assets/jquery.imageCache.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@


$(document).ready(function () { $(document).ready(function () {
$(self).each(function (i, img) { $(self).each(function (i, img) {
var src = $(img).attr('src'); var src = $(img).attr('src') || $(img).attr('data-src');
if (localStorage) { if (localStorage) {
var localSrc = localStorage[src]; var localSrc = localStorage[src];
if (localSrc) { if (localSrc) {
Expand Down
13 changes: 9 additions & 4 deletions demo.html
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -10,15 +10,20 @@
</head> </head>
<body> <body>


<h1>jQuery Image Cache plugin</h1> <h1>jQuery Image Cache plugin</h1>


<p>Images are kept in browser's Local Storage!</p> <p>Images are kept in browser's Local Storage! But, sometimes they do a request to the server to check if the image is not updated when you keep the SRC attribute.</p>


<ul> <ul>
<li><img src="assets/test-image-1.jpg" class="imageCache" /></li> <li><img src="assets/test-image-1.jpg" class="imageCache" /></li>
<li><img src="assets/test-image-2.jpg" class="imageCache" /></li> <li><img src="assets/test-image-2.jpg" class="imageCache" /></li>
<li><img src="assets/test-image-4.jpg" class="imageCache" /></li> </ul>
<li><img src="assets/test-image-5.jpg" class="imageCache" /></li>
<p>Images are kept in browser's Local Storage! No requests to the server are done because the image URL is not stored in the SRC attribute anymore but in data-src.</p>

<ul>
<li><img src="" data-src="assets/test-image-4.jpg" class="imageCache" /></li>
<li><img src="" data-src="assets/test-image-5.jpg" class="imageCache" /></li>
</ul> </ul>


<script type="text/javascript"> <script type="text/javascript">
Expand Down

0 comments on commit 812c5e9

Please sign in to comment.