All Projects → aprice → Embed

aprice / Embed

Licence: mit
Static content embedding for Golang

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Labels

Projects that are alternatives of or similar to Embed

Webmarkupmin
The Web Markup Minifier (abbreviated WebMarkupMin) - a .NET library that contains a set of markup minifiers. The objective of this project is to improve the performance of web applications by reducing the size of HTML, XHTML and XML code.
Stars: ✭ 312 (+231.91%)
Mutual labels:  minify
Uglifier
Ruby wrapper for UglifyJS JavaScript compressor.
Stars: ✭ 601 (+539.36%)
Mutual labels:  minify
Pg Minify
Minifies PostgreSQL scripts.
Stars: ✭ 37 (-60.64%)
Mutual labels:  minify
Tinyify
a browserify plugin that runs various optimizations, so you don't have to install them all manually. makes your bundles tiny!
Stars: ✭ 392 (+317.02%)
Mutual labels:  minify
Imagemin
[Unmaintained] Minify images seamlessly
Stars: ✭ 4,948 (+5163.83%)
Mutual labels:  minify
Leanify
lightweight lossless file minifier/optimizer
Stars: ✭ 694 (+638.3%)
Mutual labels:  minify
Uglifycss
Port of YUI CSS Compressor from Java to NodeJS
Stars: ✭ 259 (+175.53%)
Mutual labels:  minify
Flask Htmlmin
Flask html response minifier
Stars: ✭ 66 (-29.79%)
Mutual labels:  minify
Packem
📦⚡ A precompiled JavaScript module bundler
Stars: ✭ 586 (+523.4%)
Mutual labels:  minify
Gulp Boilerplate
A boilerplate for building web projects with Gulp.js.
Stars: ✭ 840 (+793.62%)
Mutual labels:  minify
Node Minify
Light Node.js module that compress javascript, css and html files
Stars: ✭ 404 (+329.79%)
Mutual labels:  minify
Minify
✂️ An ES6+ aware minifier based on the Babel toolchain (beta)
Stars: ✭ 4,303 (+4477.66%)
Mutual labels:  minify
Gulp Htmlmin
Minify HTML
Stars: ✭ 720 (+665.96%)
Mutual labels:  minify
Compress Images
Minify size your images. Image compression with extension: jpg/jpeg, svg, png, gif. NodeJs
Stars: ✭ 331 (+252.13%)
Mutual labels:  minify
Simplifyify
A simplified Browserify and Watchify CLI
Stars: ✭ 37 (-60.64%)
Mutual labels:  minify
Badge Size
🍻 Displays the size of a given file in your repository.
Stars: ✭ 277 (+194.68%)
Mutual labels:  minify
Lyo
📦 Node.js to browser - The easy way
Stars: ✭ 624 (+563.83%)
Mutual labels:  minify
Html Compress Twig
Twig extension for compressing HTML and inline CSS/JS using WyriHaximus/HtmlCompress
Stars: ✭ 72 (-23.4%)
Mutual labels:  minify
Babel Plugin Const Enum
Transform TypeScript `const` enums
Stars: ✭ 38 (-59.57%)
Mutual labels:  minify
Instantbootstrap
Instant Bootstrap is a quick and easy way to start creating bootstrap themes using LESS, SASS, GRUNT, and BOWER.
Stars: ✭ 5 (-94.68%)
Mutual labels:  minify

embed

Static content embedding for Golang, ©2017 Adrian Price. Usage indicates acceptance of the license found in the LICENSE file.

Purpose & Functionality

Embed is a tool for embedding static content files into a Go binary, to create a single, self-contained binary. Embed uses build constraints to offer a development mode that loads content from disk for rapid iteration during local development; once content is stable, you can run go generate to update the embedded content files, and then rebuild with different tags to serve the embedded content instead of the files on disk.

In addition to simply embedding content within your binary, embed will minify HTML, CSS, and JavaScript; gzip files for serving to clients that accept compressed content; and calculate checksums for handling Etag-based conditional requests.

Installation

Embedding tool: go get github.com/aprice/embed/cmd/embed

Usage library: go get github.com/aprice/embed/loader

Usage

Embed can easily be run with go generate.

//go:generate embed -c "embed.json"

To use embed, create a config file specifying what's to be generated:

{
	"RootPath": ".",
	"Recurse": true,
	"IncludePattern": "",
	"ExcludePattern": "(^\\.|\\.go$)",
	"OutputPath": "embedded.go",
	"BuildConstraints": "",
	"PackageName": "embedded",
	"DevOutputPath": "",
	"DevBuildConstraints": "",
	"MinifyTypes": {
		"\\.html?$": "text/html",
		"\\.css$": "text/css",
		"\\.js$": "application/javascript"
	},
	"CompressPattern": "\\.(css|js|html)$",
	"NoCompressPattern": "\\.(jpe?g|png|gif|woff2?|eot|ttf|ico)$",
	"OverrideModDate": false
}

The values above are the defaults.

RootPath is the directory where source files to be embedded will be scanned. If Recurse is true, subdirectories will be scanned as well. Each entry will be compared against IncludePattern and ExcludePattern; if a file does not match IncludePattern or does match ExcludePattern, it will not be included.

OutputPath is the path where the embedded content go file will be written. If BuildConstraints is not empty, it will be added to the output file; for example, "BuildConstraints": "!dev" will result in a file that will not be built by a build command including -tags="dev". PackageName is the package name that will be used for the output file.

DevOutputPath and DevBuildConstraints work the same as their non-Dev counterparts, but apply to a separate "dev mode" file; if DevOutputPath is not empty, a dev mode file will be written which reads all content from disk instead of using embedded content. This allows for rapid iteration during local development. The dev mode file will use PackageName for its package.

MinifyTypes is a mapping of file name regular expressions to content types that should be minified. Minifiers are enabled for text/html, text/css, text/javascript (or application/javascript), and image/svg+xml. Any other content type (or an empty content type) will not be minified. The minifier used is github.com/tdewolff/minify.

CompressPattern is a regular expression matching file names that should be gzip compressed for clients that accept compressed data. NoCompressPattern is for excluding files which otherwise match CompressPattern.

If OverrideModDate is true, the modification date for embedded files will be set to the timestamp when generation is run; otherwise, it will be the modification date of the source files.

Referencing Embedded Content

To reference embedded content, call the GetEmbeddedContent() function in the package where your generated file was created. This returns a Loader, which can be used directly as an http.Handler to serve the embedded content the same as http.FileServer(http.Dir(RootPath)). It also exposes a GetContents() method, for loading embedded content as a byte slice for programmatic use, such as embedding template 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].