Optimize Your Application
When your visual application is ready to be staged and published, you can optimize each application's resources to reduce load times and network traffic. Optimization minifies application images and stylesheets, and creates RequireJS bundles in the embedded build server that prepares your application for staging and publishing.
Sample build.json
Configurations for Optimization
When an app is enabled for optimization, you can define your own build configuration to specify the resources you want to include and exclude in the application's optimized resources bundle. You do this in the build.json
file, which you can access by clicking under Optimization in the app-level Settings editor, or under webApps/app_name/settings/
in Source view.
Include all resources and exclude specific ones
.*(\\.(js|json|html|css))$
to an optimized resources bundle named vb-app-bundle
. Here's a look at the default settings:{
"optimize": true,
"configuration": {
"bundles": {
"vb-app-bundle": {
"modules": {
"find": [
".*(\\.(js|json|html|css))$"
]
}
}
}
}
}
bcrypt.min
and crypto-js
(defined for the deal-registration
flow). In this case, here's how you might define build.json
:{
"optimize": true,
"configuration": {
"bundles": {
"vb-app-bundle": {
"modules": {
"find": [
".*(\\.(js|json|html|css))$",
"!bcrypt.min",
"!^flows/deal-registration/crypto-js",
]
}
}
}
}
}
The find
element specifies a list of regular expressions that are matched against your application. Regular expressions starting with an exclamation mark (!) are considered negative, so resources matching these patterns are not included.
Include and exclude specific resources
vb-app-bundle
, but excludes the fontawesome
file:{
"optimize": true,
"configuration": {
"bundles": {
"vb-app-bundle": {
"modules": {
"find": [
"app-flow.js",
"^build",
"!^build/components/oj-odcs/2.5.1/fontawesome"
"^flows/",
"^pages/",
"^resources/strings",
"^resources/css",
"^services/",
]
}
}
}
}
}
How you organize your app's resources into bundles depends on your application's structure as well as what you deem critical for application start. Try to bundle resources in such a way that what's really needed by the application is placed in one bundle while the rest goes into one or more other bundles.
- One for all resources that belong to the application flow
dashboard
. This bundle includes all files that match theflows/dashboard
pattern (in other words, all pages, modules, resources, and nested flows stored in theflows/dashboard
directory). It, however, excludes thehelpers
module, referred by one of the page modules. - Two for resources that belong to the application flow
customers
. In this case, nested flows (which are placed into a separate bundle later on) are excluded—as is the referredhelpers
module. - Three for resources that belong to nested flows of the
customers
flow.
In addition to these three bundles, a fourth base
bundle includes application resources, such as shell pages, libraries, and styles. This bundle explicitly adds the referred helpers
module.
{
"optimize": true,
"configuration": {
"bundles": {
"dashboard": {
"modules": {
"find": [
"flows/dashboard"
]
},
"exclude": {
"ids": [
"helpers"
]
}
},
"customers": {
"modules": {
"find": [
"flows/customers",
"!flows/customers/flows"
]
},
"exclude": {
"ids": [
"helpers"
]
}
},
"customers-nested": {
"modules": {
"find": [
"flows/customers/flows"
]
}
},
"base": {
"modules": {
"find": [
"app-flow.js",
"^pages/",
"resources/strings",
"resources/css"
],
"ids": [
"helpers"
]
}
}
}
}
}
Exclude resources using emptyPaths
resources/components/mycomponent
that references ckeditor
), you might want to include the component in your bundle but not the third-party library. To do this, you can use "!^resources/components/mycomponent/ckeditor"
in build.json
. But the library will still be included if code in your bundle references it. It may be code in the custom web component itself, or something in a file that refers to this library, for example, code in the app-flow.js
file included in the bundle that refers to 'resources/components/mycomponent/ckeditor'
. In such cases, you can add the emptyPaths
element to build.json
to ignore the dependency and also not recursively traverse its sub-dependencies:{
"optimize": true,
"configuration": {
"emptyPaths": ["ckeditor"],
"bundles": {
"dashboard": {
"modules": {
"find": [
"flows/dashboard"
]
},
"exclude": {
"ids": [
"helpers"
]
}
},
"base": {
"modules": {
"find": [
"app-flow.js",
...
emptyPaths
definition that ignores multiple libraries: {
"optimize": true,
"configuration": {
"emptyPaths": [
"ckeditor",
"ckeditor-jquery"
],
...
How to Migrate Gruntfile.js
Configuration Into build.json
If you use Grunt tasks to optimize your application, you can easily migrate configuration you've already defined in the Gruntfile.js
file into build.json
.
- Open your application's
Gruntfile.js
(located at the root of your visual application in Source view). - Look for the
bundles
element inGruntfile.js
, which you can now copy and paste intobuild.json
(located underwebApps/app_name/settings/
in Source view). Remember to fix the syntax for JSON schema.For example, here's a side-by-side comparison of thebundles
configuration inGruntfile.js
andbuild.json
:Gruntfile.js build.json 'use strict'; module.exports = (grunt) => { require('load-grunt-tasks')(grunt); grunt.initConfig({ "vb-require-bundle": { "merge-test": { options: { transpile: false, minify: false, bundles: { 'vb-app-bundle': { modules: { find: [ '.*(\\.(js|json|html|css))$', '!bcrypt.min', '!^flows/deal-registration/crypto-js', ] } } } } } } }); };
{ "optimize": true, "configuration": { "bundles": { "vb-app-bundle": { "modules": { "find": [ ".*(\\.(js|json|html|css))$", "!bcrypt.min", "!^flows/deal-registration/crypto-js", ] } } } } }