Skip to content

Instantly share code, notes, and snippets.

@endymion1818
Last active September 5, 2017 09:10
Show Gist options
  • Save endymion1818/b9f3a1fac093054cb53e9299a1ae6917 to your computer and use it in GitHub Desktop.
Save endymion1818/b9f3a1fac093054cb53e9299a1ae6917 to your computer and use it in GitHub Desktop.
timeout add custard - write these files to the document if conditions for extra custard are met
// Mustard Cutting
if ('querySelector' in document && 'addEventListener' in window) {
// add class to HTML tag
(function(H){H.className=H.className.replace(/\bno-js\b/,'js')})(document.documentElement);
// load critical scripts
document.write(unescape("%3Cscript src='assets/js/whatcananimate-criticalscripts.min.js' type='text/javascript' defer%3E%3C/script%3E"));
// add custard if screen size is big enough
var windowWidth = document.body.clientWidth;
if(windowWidth > 768){
// load scripts - from cdn but with a fallback if we can't connect
document.write(unescape("%3Cscript src='https://cdnjs.cloudflare.com/ajax/libs/gsap/1.19.0/TweenMax.min.js' type='text/javascript'%3E%3C/script%3E"));
document.write(unescape("%3Cscript src='https://cdnjs.cloudflare.com/ajax/libs/ScrollMagic/2.0.5/ScrollMagic.min.js' type='text/javascript'%3E%3C/script%3E"));
setTimeout(function() {
if (typeof TweenMax == 'undefined') {
document.write(unescape("%3Cscript src='assets/js/gsap-tweenmax.min.js' type='text/javascript'%3E%3C/script%3E"));
}
if (typeof ScrollMagic == 'undefined') {
document.write(unescape("%3Cscript src='assets/js/scrollmagic.min.js' type='text/javascript'%3E%3C/script%3E"));
}
},
// timeout delay
1000
);
// lastly, load local scripts
document.write(unescape("%3Cscript src='assets/js/whatcananimate-criticalscripts.min.js' type='text/javascript' defer%3E%3C/script%3E"));
}
};
@endymion1818
Copy link
Author

These are meant to be written before the closing </body> tag. This is so that we can load larger filed from a CDN but provide a fallback if necessary. Also, if the screen is a small size, we disable some of the fancier javascript that's better displayed on desktops.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment