Skip to content

Instantly share code, notes, and snippets.

@chrishamant
Created April 28, 2011 07:30
Show Gist options
  • Save chrishamant/945956 to your computer and use it in GitHub Desktop.
Save chrishamant/945956 to your computer and use it in GitHub Desktop.
Simple asyncscript loader
#analytics stuff
_gaq = [['_setAccount','UA-XX-1'],['_trackPageview']]
d = window.document
l = d.location
scripts = [
'//google-analytics.com/ga.js',
'//ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js',
'//' + l.host + '/js/site.js'
]
getScript = (src)->
s = d.createElement 'script'
s.async = true
s.src = src
e = (d.getElementsByTagName('script')[0])
e.parentNode.insertBefore(s,e)
getScript(script) for script in scripts
#this is the kind of thing you'd need to do in site.js before you can expect jQuery to work
# what if your site.js loaded before jQuery?
if jQuery then init() else window.setTimeout(ready,0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment