All Projects → matryer → mix

matryer / mix

Licence: MIT license
Go http.Handler that mixes many files into one request.

Programming Languages

go
31211 projects - #10 most used programming language
javascript
184084 projects - #8 most used programming language

mix GoDoc

Go http.Handler that mixes many files into one request.

  • Trivial to use
  • Each file will only be included once, despite how many times it might match a pattern
  • Uses Glob (from go-zglob) providing familiar filepath patterns
  • Uses http.ServeContent so all headers are managed nicely

Go from this:

<script src="https://github.com/js/base.js"></script>
<script src="https://github.com/js/analytics.js"></script>
<script src="https://github.com/js/controls.js"></script>
<script src="https://github.com/js/auth.js"></script>
<script src="https://github.com/js/api.js"></script>

to this:

<script src="https://github.com/mix/all.js"></script>

Usage

go get gopkg.in/matryer/mix.v2

If you have a directory containing many JavaScript files:

files/
  js/
    one.js
    two.js
    three.js
  lib/
    four.js

You can use mix.Handler to specify filepath patterns to serve them all in a single request.

http.Handle("/mix/all.js", mix.New("./files/js/*.js", "./files/lib/*.js"))
  • The Content-Type will be taken from the request path.

Notes

App engine

It's important to remember that files marked as static with static_dir or static_file in App Engine are not available to your Go code. So mix cannot work on those files. Instead, you should structure your app so that mixable content lives in a different directory to your static files.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].