Last active
August 29, 2015 14:01
-
-
Save flexbox/1832f48d92f1bee693ce to your computer and use it in GitHub Desktop.
[blog] - small snippet for http://davidl.fr/blog/site-web-obese.html
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
<-- 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