Created
April 5, 2012 19:33
-
-
Save cfjedimaster/2313466 to your computer and use it in GitHub Desktop.
Conditional jQuery resource get
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Conditional Get</title> | |
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script> | |
<script> | |
$(document).ready(function() { | |
var theResource = "dump.zip"; | |
if(localStorage["resourcemodified"]) { | |
$.ajax({ | |
url:theResource, | |
type:"head", | |
success:function(res,code,xhr) { | |
console.log("comparing mine "+ localStorage["resourcemodified"] + " to "+ xhr.getResponseHeader("Last-Modified")) | |
if(localStorage["resourcemodified"] != xhr.getResponseHeader("Last-Modified")) getResource(); | |
} | |
}) | |
} else getResource(); | |
function getResource() { | |
$.ajax({ | |
url:theResource, | |
type:"get", | |
cache:false, | |
success:function(res,code,xhr) { | |
localStorage["resourcemodified"] = xhr.getResponseHeader("Last-Modified"); | |
console.log("done getting it"); | |
} | |
}) | |
} | |
}); | |
</script> | |
</head> | |
<body> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment