Skip to content

Commit

Permalink
Made the bootstrap and jquery resources be served by CDN in prod
Browse files Browse the repository at this point in the history
  • Loading branch information
levpaul committed Jul 15, 2015
1 parent f904700 commit c714c28
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
32 changes: 32 additions & 0 deletions controllers/template_functions.go
@@ -0,0 +1,32 @@
package controllers

import (
"github.com/astaxie/beego"
)

func init() {
beego.AddFuncMap("jquerySource", jquerySource)
beego.AddFuncMap("bootstrapJavascriptSource", bootstrapJavascriptSource)
beego.AddFuncMap("bootstrapCSSSource", bootstrapCSSSource)
}

func jquerySource() string {
if beego.RunMode == "prod" {
return "//code.jquery.com/jquery-1.11.3.min.js"
}
return "static/js/jquery.min.js"
}

func bootstrapJavascriptSource() string {
if beego.RunMode == "prod" {
return "//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"
}
return "static/js/bootstrap.min.js"
}

func bootstrapCSSSource() string {
if beego.RunMode == "prod" {
return "//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"
}
return "static/css/bootstrap.min.css"
}
6 changes: 3 additions & 3 deletions views/common/head.tpl
Expand Up @@ -7,7 +7,7 @@

<title>Mulligan Calculator</title>

<link href="static/css/bootstrap.min.css" rel="stylesheet">
<link href="{{bootstrapCSSSource}}" rel="stylesheet">
<link href="static/css/sticky-footer.css" rel="stylesheet">
<link href="static/css/style.css" rel="stylesheet">

Expand All @@ -19,6 +19,6 @@
<![endif]-->

<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="static/js/jquery.min.js"></script>
<script src="{{jquerySource}}"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="static/js/bootstrap.min.js"></script>
<script src="{{bootstrapJavascriptSource}}"></script>

0 comments on commit c714c28

Please sign in to comment.