Skip to content

Instantly share code, notes, and snippets.

@draggor
Created September 17, 2010 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save draggor/584300 to your computer and use it in GitHub Desktop.
Save draggor/584300 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>index</title>
<meta name="generator" content="TextMate http://macromates.com/">
<meta name="author" content="arcus">
<!-- Date: 2010-08-04 -->
<script src="jquery.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
$.noConflict();
// Cache Holder
var cachey_cache = {};
var $ = function(sel) {
if(sel instanceof Function) {
return jQuery(sel);
}
var arg2 = arguments[1];
if (cachey_cache[sel]) {
// If selector esists return the cached version
return cachey_cache[sel];
} else {
// Otherwise return the selected object and add it to the cache holder
return cachey_cache[sel] = jQuery(sel);
}
};
// Testing Code
$(function() {
alert($("#test").html());
alert($("#test").html()); // This selection will be cached
});
</script>
</head>
<body>
<div id="test">hello world</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment