martini-bundle
adds resource bundling and minification to Martini.
Install all the packages (go 1.1 and greater is required):
go get github.com/fjdumont/martini-bundle/...
and
import "github.com/fjdumont/martini-bundle/scriptbundle"
import "github.com/fjdumont/martini-bundle/stylebundle"
martini-bundle/scriptbundle
adds concatenation, scope wrapping and minification to your JavaScript files.
- concatenation: simply concatenates all file contents
- scope wrapping: wraps an IIFE/IFFY/SIAF around the concatenated scripts
- minification: uses the Closure Compiler Service REST API to minify your scripts
Simply use scriptbundle.Default(files ...string)
as a martini.Handler
to register your script files as a bundle:
m := martini.Classic()
m.Get("/js/app.js", scriptbundle.Default(
"public/js/jquery.js",
"public/js/app-utils.js",
"public/js/app.js",
))
Alternatively, plug your own scriptbundle.Options
into scriptbundle.Bundle(opts *scriptbundle.Options, files ...string)
to customize your optimizations:
type Options struct {
Wrap bool
Minify bool
}
martini-bundle/stylebundle
adds concatenation and minification to your Styleseets.
- concatenation: simply concatenates all file contents
- minification: uses the CSS Minifier REST API to minify your styles
Use stylebundle.Default(files ...string)
as a martini.Handler
to compile your styles into a bundle and use them:
m := martini.Classic()
m.Get("/css/app.css", stylebundle.Default(
"public/js/vendor/bootstrap.css",
"public/js/vendor/bootstrap-responsive.css",
"public/js/app.css",
))
Alternatively, plug your own stylebundle.Options
into stylebundle.Bundle(opts *stylebundle.Options, files ...string)
to customize your optimizations:
type Options struct {
Minify bool
}