let's try moving external script loading back to app.on('render') so

ew don't cause blocking on failed amazon affiliate load
This commit is contained in:
Tyler Renelle 2013-05-01 13:07:42 +01:00
parent 02f3a185f1
commit 584eb3e936
2 changed files with 20 additions and 31 deletions

View file

@ -184,6 +184,21 @@ module.exports.resetDom = (model) ->
# Note, Google Analyatics giving beef if in this file. Moved back to index.html. It's ok, it's async - really the
# syncronous requires up top are what benefit the most from this file.
googleAnalytics = (model) ->
if model.flags.nodeEnv is 'production'
window._gaq = [["_setAccount", "UA-33510635-1"], ["_setDomainName", "habitrpg.com"], ["_trackPageview"]]
$.getScript ((if "https:" is document.location.protocol then "https://ssl" else "http://www")) + ".google-analytics.com/ga.js"
amazonAffiliate = (model) ->
if model.get('_loggedIn') and (model.get('_user.flags.ads') != 'hide')
$.getScript('//wms.assoc-amazon.com/20070822/US/js/link-enhancer-common.js?tag=ha0d2-20').fail ->
$('body').append('<img src="//wms.assoc-amazon.com/20070822/US/img/noscript.gif?tag=ha0d2-20" alt="" />')
googleCharts = ->
$.getScript "//www.google.com/jsapi", ->
# Specifying callback in options param is vital! Otherwise you get blank screen, see http://stackoverflow.com/a/12200566/362790
google.load "visualization", "1", {packages:["corechart"], callback: ->}
module.exports.app = (appExports, model, app) ->
loadJavaScripts(model)
setupGrowlNotifications(model) unless model.get('_mobileDevice')
@ -208,7 +223,7 @@ module.exports.app = (appExports, model, app) ->
$.getScript('//checkout.stripe.com/v2/checkout.js')
unless (model.get('_mobileDevice') is true)
$.getScript("//s7.addthis.com/js/250/addthis_widget.js#pubid=lefnire")
# Google Charts
$.getScript "//www.google.com/jsapi", ->
# Specifying callback in options param is vital! Otherwise you get blank screen, see http://stackoverflow.com/a/12200566/362790
google.load "visualization", "1", {packages:["corechart"], callback: ->}
googleCharts()
googleAnalytics(model)
amazonAffiliate(model)

View file

@ -41,30 +41,4 @@
<app:tasks:taskLists />
</div>
</div>
<app:footer:footer />
<Scripts:>
{{#if equal(_nodeEnv,"production")}}
<!-- Google Analytics -->
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-33510635-1']);
_gaq.push(['_setDomainName', 'habitrpg.com']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
{{/}}
{{#if and( _loggedIn, notEqual(_user.flags.ads,'hide') )}}
<script type="text/javascript" src="//wms.assoc-amazon.com/20070822/US/js/link-enhancer-common.js?tag=ha0d2-20">
</script>
<noscript>
<img src="//wms.assoc-amazon.com/20070822/US/img/noscript.gif?tag=ha0d2-20" alt="" />
</noscript>
{{/}}
<app:footer:footer />