Skip to content

Instantly share code, notes, and snippets.

@flexbox
Last active August 29, 2015 14:01
Show Gist options
  • Save flexbox/1832f48d92f1bee693ce to your computer and use it in GitHub Desktop.
Save flexbox/1832f48d92f1bee693ce to your computer and use it in GitHub Desktop.
[blog] - small snippet for http://davidl.fr/blog/site-web-obese.html
<-- Script tag that will hold jQuery -->
<script id="js-jquery"></script>
<-- Determine if jQuery should be loaded from localStorage or the server -->
<script>
var jqFile;
if ('jqFile' in window.localStorage) {
// 1. The script is already stored
jqFile = window.localStorage.getItem('jqFile');
} else {
// 2. not present, AJAX request to get the data
jqFile = getJQFile();
// push the data into localStorage
window.localStorage.setItem('jqFile',jqFile);
}
// 3. Insert JavaScript into the script element
document.getElementById('js-jquery').text = jqFile;
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment