Skip to content

Instantly share code, notes, and snippets.

@RinatValiullov
Forked from gaearon/minification.md
Created April 24, 2019 06:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RinatValiullov/c89c15dedf556738eaebbeacc98b8cfd to your computer and use it in GitHub Desktop.
Save RinatValiullov/c89c15dedf556738eaebbeacc98b8cfd to your computer and use it in GitHub Desktop.
How to Set Up Minification

In production, it is recommended to minify any JavaScript code that is included with your application. Minification can help your website load several times faster, especially as the size of your JavaScript source code grows.

Here's one way to set it up:

  1. Install Node.js
  2. Run npm init -y in your project folder (don't skip this step!)
  3. Run npm install terser

Now, to minify a file called like_button.js, run in the terminal:

npx terser -c -m -o like_button.min.js -- like_button.js

This will produce a file called like_button.min.js with the minified code in the same directory. If you're typing this often, you can create an npm script to give this command a name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment