The GitHub pages build service cannot have any other code running on it other than Jekyll in safe mode and the small number of included plugins. This is done for security.

Your best option is to use an alternative service to build your site and push the result back to GitHub. The source for the site would reside in the master branch and the compiled source in gh-pages.

A suitable service for doing so would be one of many CI services, such as Travis CI. These are typically used to run software test suites on every push to a repo, but can be used to build your website and push the result back to you.


The Jekyll docs have a guide for testing builds on Travis. Pushing the output isn't mentioned. You'll need a script in the after_success derivative in the Travis conf file. An example from a site I maintain.

To authenticate your push the script will need access to your github personal access token. You can't just put this straight in the deploy script as it's a secret. See the Travis docs on encrypting environment variables.

Answer from wjdp on Stack Overflow
🌐
GitHub
github.com › coderaiser › minify
GitHub - coderaiser/minify: Minifier of js, css, html and img · GitHub
Minifier of js, css, html and img. Contribute to coderaiser/minify development by creating an account on GitHub.
Author   coderaiser
🌐
GitHub
github.com › wilsonzlin › minify-js
GitHub - wilsonzlin/minify-js: Extremely fast JavaScript minifier, available for Rust and Node.js · GitHub
Extremely fast JavaScript minifier, available for Rust and Node.js - wilsonzlin/minify-js
Author   wilsonzlin
🌐
GitHub
github.com › mrclay › minify
GitHub - mrclay/minify: Combines. minifies, and serves CSS or Javascript files
Minify is an HTTP server for JS and CSS assets.
Starred by 3K users
Forked by 468 users
Languages   PHP 78.3% | CSS 11.2% | JavaScript 7.0% | HTML 3.0% | Less 0.3% | SCSS 0.1% | Shell 0.1%
🌐
GitHub
github.com › tdewolff › minify
GitHub - tdewolff/minify: Go minifiers for web formats · GitHub
Optionally, one can enable java -jar build/compiler.jar to run for JS (for example the ClosureCompiler). Note that reading the file into a buffer first and writing to a pre-allocated buffer would be faster (but would disable streaming). package main import ( "log" "os" "os/exec" "github.com/tdewolff/minify/v2" "github.com/tdewolff/minify/v2/css" "github.com/tdewolff/minify/v2/html" "github.com/tdewolff/minify/v2/js" "github.com/tdewolff/minify/v2/json" "github.com/tdewolff/minify/v2/svg" "github.com/tdewolff/minify/v2/xml" ) func main() { m := minify.New() m.AddFunc("text/css", css.Minify) m.A
Author   tdewolff
🌐
GitHub
gist.github.com › gaearon › 42a2ffa41b8319948f9be4076286e1f3
How to Set Up Minification · GitHub
Clone this repository at <script src="https://gist.github.com/gaearon/42a2ffa41b8319948f9be4076286e1f3.js"></script> Save gaearon/42a2ffa41b8319948f9be4076286e1f3 to your computer and use it in GitHub Desktop. ... In production, it is recommended to minify any JavaScript code that is included with your application.
🌐
GitHub
github.com › minify-js › minify-js.github.io
GitHub - minify-js/minify-js.github.io: Minify HTML, CSS, and JavaScript files.
Minify HTML, CSS, and JavaScript files. Contribute to minify-js/minify-js.github.io development by creating an account on GitHub.
Starred by 4 users
Forked by 3 users
Languages   HTML 50.9% | JavaScript 44.5% | CSS 4.6%
Top answer
1 of 5
9

The GitHub pages build service cannot have any other code running on it other than Jekyll in safe mode and the small number of included plugins. This is done for security.

Your best option is to use an alternative service to build your site and push the result back to GitHub. The source for the site would reside in the master branch and the compiled source in gh-pages.

A suitable service for doing so would be one of many CI services, such as Travis CI. These are typically used to run software test suites on every push to a repo, but can be used to build your website and push the result back to you.


The Jekyll docs have a guide for testing builds on Travis. Pushing the output isn't mentioned. You'll need a script in the after_success derivative in the Travis conf file. An example from a site I maintain.

To authenticate your push the script will need access to your github personal access token. You can't just put this straight in the deploy script as it's a secret. See the Travis docs on encrypting environment variables.

2 of 5
3

If you are using Github to generate the site and display it, there is no option to do this because Github is strict about what it will process - for security.

A workaround is to do your compiling and processing locally, then push the resulting output to to gh-pages - which is happy to simply host static pages.

You can still use github to host the project. You just do not use Github to compile it.

Your dev process might be:

  1. Check you're master and local match.
  2. Do your work in dev mode.
  3. Build in production.
  4. Use grunt or other program to minify/uglify/etc the _site production files - outputting to a separate dist (distribution) folder.
  5. Push the contents of the dist folder to your gh-pages.
  6. Commit changes to the project files back to the master.

I am probably not making much sense, but perhaps this discussion might help more: https://gist.github.com/cobyism/4730490

Have fun!

Find elsewhere
🌐
GitHub
github.com › marketplace › actions › minify-js-action
Minify-JS Action - GitHub Marketplace
Github action to minify html, javascript and css files, using minify. First you need to check out your repository, then configure the Minify-JS job, at the end you can commit to your repository.
🌐
GitHub
github.com › juancarlospaco › css-html-js-minify
GitHub - juancarlospaco/css-html-js-minify: StandAlone Async cross-platform Minifier for the Web.
StandAlone Async cross-platform Unicode-ready Python3-ready Minifier for the Web. positional arguments: fullpath Full path to local file or folder. optional arguments: -h, --help show this help message and exit --version show programs version number and exit --wrap Wrap output to ~80 chars per line, CSS only. --prefix PREFIX Prefix string to prepend on output filenames. --timestamp Add a Time Stamp on all CSS/JS output files.
Starred by 215 users
Forked by 20 users
Languages   Python
🌐
GitHub
github.com › JossyDevers › minify-js
GitHub - JossyDevers/minify-js: Minify html, javascript and css files.
Minify html, javascript and css files. Contribute to JossyDevers/minify-js development by creating an account on GitHub.
Starred by 6 users
Forked by 10 users
Languages   Shell 88.9% | Dockerfile 11.1%
🌐
GitHub
github.com › topics › javascript-minifier
Build software better, together
Simple JavaScript minifier written in Python. ... Python based tool for processing website files for maximum efficiency on hosted speed and bandwidth. Also applies versioning to file names in order to allow hosting to have maximum cache for ...
🌐
GitHub
github.com › fizker › minifier
GitHub - fizker/minifier: A simple tool for minifying CSS/JS without a big setup
A simple tool for minifying CSS/JS without a big setup. ... It automatically resolves @import statements in CSS. ... Cloning directly from github.
Starred by 70 users
Forked by 8 users
Languages   JavaScript 96.0% | HTML 2.4% | CSS 1.6%
🌐
Skalman
skalman.github.io › UglifyJS-online
UglifyJS 3: Online JavaScript minifier
This is a simple wrapper for the browser around the minifier; the hard work is done by the Uglify team. If you need an automated solution, I suggest checking out the source code, intended for Node.JS. Do you want to help improve this tool? It's on Github.
🌐
GitHub
github.com › kangax › html-minifier
GitHub - kangax/html-minifier: Javascript-based HTML compressor/minifier (with Node.js support) · GitHub
Sample command line: html-minifier --collapse-whitespace --remove-comments --remove-optional-tags --remove-redundant-attributes --remove-script-type-attributes --remove-tag-whitespace --use-short-doctype --minify-css true --minify-js true
Author   kangax
🌐
GitHub
github.com › topics › js-minifier
js-minifier · GitHub Topics · GitHub
cli npm npm-package html-minifier minifier css-minifier js-minifier portfolio-include json-minifier ... CSS and JS Minifiier written in PHP.