Skip to content

Minify static files

Cristian Gonzalez edited this page Jul 8, 2021 · 1 revision

Minify static files

UNCode has several static files, this is JavaScript and CSS files. These files are minified in order to give a bit of security (they are less readable) and to decrease the payload of UNCode for slow connections.

To minify these static files, there are two types: the all-minified.js file, which comes from the original repository (INGInious). The other type are the minfiles for the different plugins, which in most cases must be updated before merging to master. This guide shows how to update the different minified files.

Minify plugins

This utility allows you to automatically minify css and js files for each plugin on UNCode. You can find this utility in the INGInious repository in utils/minify_plugins.

All the code and logic is in the script minify_plugins.js. This uses terser to minify JavaScript files, and for CSS files, Clean CSS is used.

Minify new plugins

In case a new plugin is added, you have to update the minify_plugins.js script, For that, a separate function is created for each plugin, please see how this is done for the other plugins and read the documented functions.

Run minifier

Before you start, you must install node 10.x or a greater version and npm. After that, you have to install the dependencies:

npm install

To update or create minified files for all plugins, run:

npm run minify

Plugins

The plugins being minified are:

  • UNCode.
  • UN template.
  • Statistics.
  • Register students.
  • Multilang.
  • Grader generator.
  • Code preview.
  • Analytics.
  • Plagiarism.
  • Task editorial
  • Contact page
  • Manual scoring
  • Task hints
  • Course creation

Some of this plugins, generate more than one minified file, for example, multilang.

Minify all-minified.js file

This file must be updated when of the files in inginious/frontend/static/js are modified. For that, another tool, similar to the previous one, is provided. This utility uses a tool called Grunt, which minifies the configured files.

To start the minifier and update the file, go to the folder utils/minify/, and follow the next steps:

  1. (Optional) Install Grunt in case it is not installed:

    npm install -g grunt-cli
  2. Go to the utility folder:

    cd utils/minify/
  3. Install the dependencies

    npm install
  4. Run Grunt

    grunt

If everything was correct and the INGInious static files changed, the file all-minified.js should contain the new changes.

Clone this wiki locally