Steal will be able to declare packages like:
steal.packages('contacts','login','filemanager')
This tells the builder to build contacts, login, and filemanager packages that can be progressively loaded later. In development, when code runs like:
steal('contacts', function(){ ... })
Steal will simply steal contacts/contacts.js
and anything it steals that hasn't already been stolen.
But in production, instead of stealing contacts/contacts.js
, it will steal app/packages/contacts.js
. app/packages/contacts.js
will be comprised of contacts/contacts.js
and the steals unique to contacts/contacts.js
.
In summary, packages tells steal that other resources will be loaded and to package and minify them in an efficient way for progressive loading. In the app's production.js, it tells it where to find these packages.
Example
Packages lets you define several parts of your application to progressively load. In this example, we want to load only what is needed to get the application started and defer the rest until we know if the user has logged in or not. The following is done with 3.3 code:
// tell steal that you want to build these as packages
steal.packages('contacts','login','filemanager')
// load the minimum you need to start your app
.then('jquery/controller/route',
function(){
// checks if the user logged in or not
// we might get this from the page
$.ajax({
url: '/curuser',
success: function(){
// if the user is, start routing
new Router(window);
},
error : function(){
// otherwise load the login code
steal('login')
}
});
// a router that listens to hashchange and loads modules on demand.
$.Controller('Router',{
"contacts route" : function(){
steal('contacts', function(){
// setup contacts
})
},
"filemanger route" : function(){
steal('filemanager', function(){
// setup filemanager
})
}
})
})
Impact
This makes progressive loading very simple. You define the parts of the app you want to load later and steal them naturally in development mode.
Steal's build system will make sure to package them as efficiently as possible. In fact, dependencies between packages are packaged themselves to improving caching and minimize load times.
When it comes time to build, everything just 'works'. No configuration files!
I believe this will be a game-changer. It provide the fastest possible load times for complex apps in a straightforward manner.