start moving javascript loading functionality back to <Scripts:> so we

can utilize CDNs
This commit is contained in:
Tyler Renelle 2013-03-15 11:15:35 -04:00
parent 565c9004ca
commit 2f372124b3
2 changed files with 16 additions and 20 deletions

View file

@ -20,41 +20,27 @@ restoreRefs = module.exports.restoreRefs = (model) ->
###
Loads JavaScript files from (1) public/js/* and (2) external sources
We use this file (instead of <Scripts:> or <Tail:> inside .html) so we can utilize require() to concatinate for
faster page load, and $.getScript for asyncronous external script loading
If a library is available in a CDN, we put it in <Scripts:> (index.html) for better caching. If not, we use
this function to utilize require() to concatinate for faster page load, and $.getScript for asyncronous external script loading
###
loadJavaScripts = (model) ->
require '../../public/vendor/jquery-ui/jquery-1.9.1'
unless model.get('_view.mobileDevice')
require '../../public/vendor/jquery-ui/ui/jquery.ui.core'
require '../../public/vendor/jquery-ui/ui/jquery.ui.widget'
require '../../public/vendor/jquery-ui/ui/jquery.ui.mouse'
require '../../public/vendor/jquery-ui/ui/jquery.ui.sortable'
# Bootstrap
require '../../public/vendor/bootstrap/docs/assets/js/bootstrap'
# require '../../public/vendor/bootstrap/js/bootstrap-tooltip'
# require '../../public/vendor/bootstrap/js/bootstrap-tab'
# require '../../public/vendor/bootstrap/js/bootstrap-popover'
# require '../../public/vendor/bootstrap/js/bootstrap-modal'
# require '../../public/vendor/bootstrap/js/bootstrap-dropdown'
require '../../public/vendor/jquery-cookie/jquery.cookie'
require '../../public/vendor/bootstrap-tour/bootstrap-tour'
require '../../public/vendor/bootstrap-datepicker/js/bootstrap-datepicker'
require '../../public/vendor/bootstrap-growl/jquery.bootstrap-growl.min'
# JS files not needed right away (google charts) or entirely optional (analytics)
# Each file getsload asyncronously via $.getScript, so it doesn't bog page-load
unless model.get('_view.mobileDevice')
$.getScript("https://s7.addthis.com/js/250/addthis_widget.js#pubid=lefnire");
$.getScript("//s7.addthis.com/js/250/addthis_widget.js#pubid=lefnire");
# Google Charts
$.getScript "https://www.google.com/jsapi", ->
$.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: ->}

View file

@ -38,9 +38,19 @@
<app:footer:footer />
<Scripts:>
<!-- scripts go in /src/app/browser.coffee, that way we can get min/concat -->
<!-- only the ones that are remote and can't be done async are here -->
<!-- we load as many CDN-available javascript files here as possible. For the rest,
we use /src/app/browser.coffee -> loadJavaScripts() which concats/minifies /public/vendor javascript libraries,
as well as runs async loads -->
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.3.1/jquery.cookie.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.1/js/bootstrap.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-growl/1.0.0/jquery.bootstrap-growl.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.0.0/js/bootstrap-datepicker.min.js"></script>
<script src="https://checkout.stripe.com/v2/checkout.js"></script>
{#if equal(_view.nodeEnv,"production")}
<!-- Google Analytics -->
<script type="text/javascript">