Ciel
Ciel

Reputation: 4440

Minify _WITHOUT_ combine using requireJS

My program is using RequireJS to manage dependencies in javascript, and it works fine - except that I have an issue where the only way to do the minification is to use the r.js optimization system to do minify and combine when I compile the application.

This does work; I have it functioning how I need it to - but it is very wasteful because it puts all of the scripts in a single document. This seems to defeat the entire purpose of the module loading - and it makes the site a great deal slower.

Is there a way - other than manually minifying each file, every time I change them, to have this optimizer keep files separated so that the module loading can still only pull the files it needs?

I am doing the minification/combination using nodejs with a build event in Visual Studio, similar to this;

build.bat

node minify.js -o build.json

build.json

{
    "baseUrl" : "../../home", 
    "name": "../lib/app/config", 
    "include": [
          // each file gets listed here
    ], 
    "exclude": [], 
    "optimize": "none", 
    "out": "program.js", 
    "insertRequire": [
        "../lib/app/config"
      ]
}

config.js

require.config({
    baseUrl: '/app_content/scripts',
});

Visual Studio Build Event

node "$(ProjectDir)scripts\lib\app\minify.js" -o "$(ProjectDir)scripts\lib\app\build.json"

So this makes a huge program.js file that has everything - with explicitly named modules. It runs and functions, but ... again, that kind of defeats the purpose, right?

Upvotes: 0

Views: 76

Answers (1)

jgillich
jgillich

Reputation: 76209

it makes the site a great deal slower

That can't be true, concatenating into a single file reduces the amount of necessary HTTP requests for a page and should improve performance quite a bit. If you just want to minify your files, use a tool that does just that - e.g. UglifyJS.

Upvotes: 2

Related Questions