Skip to content

Instantly share code, notes, and snippets.

@cfjedimaster
Created April 5, 2012 19:33
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cfjedimaster/2313466 to your computer and use it in GitHub Desktop.
Save cfjedimaster/2313466 to your computer and use it in GitHub Desktop.
Conditional jQuery resource get
<!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