Swaagie / minimize

Minimize HTML
MIT License
162 stars 18 forks source link

Minify inline JS - Package link broken? #78

Open berstend opened 8 years ago

berstend commented 8 years ago

I'm interested in using minimize to compress inline JS tags as well.

Unfortunately the link to the minimize uglify npm package seems to be broken: https://github.com/Swaagie/minimize#available-plugins

I couldn't find any reference to uglifyjs in the minimize code - is compressing inlined JS snippets still supported?

Swaagie commented 8 years ago

Sorry been a bit busy last weeks. This plugin is still in an uncommitted repo on my harddrive. I'll try to push it to github asap.

gmetais commented 7 years ago

Hi @Swaagie

How can I help? Would you like me to help publishing https://github.com/Swaagie/minimize-plugin-uglifyjs on npm (and than transfer the ownership to you)?

simllll commented 7 years ago

any updates on this? :)

simllll commented 7 years ago

What I did to get this working:

  1. used the index.js from minizie-plugin-uglifyjs and copied it to my project
  2. modified it to let it look like following code:
'use strict';

var uglifyjs = require('uglify-js');

//
// Unique ID to identify the plugin.
//
exports.id = 'uglifyjs';

//
// Minify the JS with uglify JS.
//
exports.element = function plugin(element, done) {
    if(!element.parent || element.parent.name != 'script') return done();

    var content, code
        , options = uglifyjs.defaults({
        fromString: true,
        compress: {//unused: false <-- doesn't make any difference
        },
        mangle: {}
    });

    // 1. parse
    content = uglifyjs.parse(element.data, options);

    // 2. compress <-- slowest part
    content.figure_out_scope();
    options.compress.screw_ie8 = true;
    options.compress.warnings = false;
    content = content.transform(uglifyjs.Compressor(options.compress));

    // 3. mangle
    options.mangle.screw_ie8 = true;
    content.figure_out_scope(options.mangle);
    content.compute_char_frequency(options.mangle);
    content.mangle_names(options.mangle);

    // 4. output
    var stream = uglifyjs.OutputStream();
    content.print(stream);
    element.data = stream.toString();
    done();
};
  1. included the plugin:
var Minimize = require('minimize')
        , jsuglify = require('./controller/thirdparty/minizime-plugin-uglify')
        , minimize = new Minimize({ plugins: [jsuglify]});

tried to optimize the performance, unfortuantely it's still at least 50% slower than without a uglifyjs2.

dickeylth commented 7 years ago

any updates on this? :)

Swaagie commented 7 years ago

After a forced break from OS (mainly time restraints) this should receive updates shortly. Last week I opened a project https://github.com/Swaagie/minimize/projects/1 to track this work.

alessioalex commented 5 years ago

ping @Swaagie can you push the branch at least so we can help you out?