Reputation: 4440
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;
node minify.js -o build.json
{
"baseUrl" : "../../home",
"name": "../lib/app/config",
"include": [
// each file gets listed here
],
"exclude": [],
"optimize": "none",
"out": "program.js",
"insertRequire": [
"../lib/app/config"
]
}
require.config({
baseUrl: '/app_content/scripts',
});
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
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