Minimize JavaScript during the build of GitHub Pages?

I have a static website through GitHub pages built on Jekyll-Bootstrap. My small website includes a lot of JavaScript and for ease of maintenance, I would like all JavaScript to remain human readable in the GitHub repository.

But for the end user of my website, I would prefer to minimize JavaScript.

Is there a way to create a hook during the build process of GitHub pages to minimize / guess JavaScript so that the end user can upload smaller files?

+5
source share
2 answers

The GitHub page creation service cannot have any other code running on it except Jekyll in safe mode and a small number of plugins are included . This is done to ensure safety.

Your best option is to use an alternative service to create your site and return the result to GitHub. The source for the site will be in the main branch and the compiled source in the gh-pages.

An appropriate service for this will be one of many CI services, such as Travis CI. They are usually used to run sets of software test programs each time you click on a repo, but can be used to create your website and return the result to you.


The Jekyll docs test guide is based on Travis. Pressing the exit is not mentioned. You will need a script in the after_success derivative in the confvis conf file. An example from a site that I support .

For authentication, click script to access the token of your github personal access. You cannot just put this directly in your deployment script, as that is a secret. See Travis Docs for Encrypting Environment Variables .

+7
source

If you use Github to create a site and display it, there is no way to do it, because Github strictly says what it will handle - for security.

The workaround is to compile and process locally, and then output the result to gh-pages - which is happy to just post static pages.

You can still use github to host the project. You just don't use Github to compile it.

Your dev process could be:

  • Check that you are a master and local match.
  • Do your work in dev mode.
  • Assembly in production.
  • Use grunt or another program to minimize / uglify / etc working _site files - output to a separate dist (distribution) folder.
  • Click the contents of the dist folder into your gh pages.
  • Make changes to the project files back to the wizard.

I probably don't quite understand, but maybe this discussion can help more: https://gist.github.com/cobyism/4730490

Good luck

+2
source

Source: https://habr.com/ru/post/1259977/


All Articles