Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Not sure why there isn't an "official" way of doing this (compared to what Ruby on Rails does).</p> <p>Here are a few suggestions:</p> <h2>DIY</h2> <p>Here's what I've been doing so far:</p> <p>At server startup, I run uglify-js on all the js files (under .../js, and create the minified version under .../min) with something like so (leaving out the reading/writing of the files):</p> <pre><code> var jsp = require('uglify-js').parser; var pro = require('uglify-js').uglify; var ast = jsp.parse(code.toString('utf8')); // parse code and get the initial AST ast = pro.ast_mangle(ast); // get a new AST with mangled names ast = pro.ast_squeeze(ast); // get an AST with compression optimizations var final_code = pro.gen_code(ast); // compressed code here </code></pre> <p>then in html templates, based on some environment variable to trigger production environment, I generate the path for the <code>&lt;script&gt;</code> tags to either point to .../js or .../min.</p> <p>This leaves out quite a lot (where you would group all js files into one minimized one to reduce the number of browser queries and such), but hopefully this can help you craft your own strategy.</p> <h2>Piler</h2> <p>That said, I've been meaning to try piler (<a href="https://github.com/epeli/piler" rel="nofollow noreferrer">https://github.com/epeli/piler</a>), which seems to be a better alternative to the DYI way.</p> <h2>Using Grunt</h2> <p>Grunt.js (<a href="http://gruntjs.com/" rel="nofollow noreferrer">http://gruntjs.com/</a>) is also quite suitable to help preprocess files (html, js, css, ...)</p> <p>Here are a few pointers:</p> <ul> <li>grunt-recess: <a href="https://github.com/sindresorhus/grunt-recess" rel="nofollow noreferrer">https://github.com/sindresorhus/grunt-recess</a> (especially interesting if you use less)</li> <li><a href="https://stackoverflow.com/questions/13358680/how-to-config-grunt-js-to-minify-files-separately">how to config grunt.js to minify files separately</a></li> <li>Grunt tasks to process HTML files and produce a deploy directory of optimized files (<a href="https://gist.github.com/necolas/3024891" rel="nofollow noreferrer">https://gist.github.com/necolas/3024891</a>)</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload