1.2 beta feature - Lazy Loading Scripts

1 view
Skip to first unread message

chris thatcher

unread,
Aug 27, 2010, 9:14:34 AM8/27/10
to jquery-...@googlegroups.com
This is one I've been hoping to get to for a long time so it was great to finally get it done. Basically you now only have to eagerly load your core configuration files and your boot file, while all models, views, and controllers can be loaded either eagerly or lazily.  You can just leave them out of your initial application bundle.

There is currently a convention for lazy load which allows some flexibility in where you put your application scripts. $.env('appbase') must be provided in environments.js or will default to { '' : '/app/' }.  This object provides a mapping for namespaces to network locations to lazy load app components from.

which means that we will try to lazy load the app component $.$('#fooController') from /app/controllers/foo.js

Lets look at some more examples

if $.env('appbase') is 
{
   '': '/myapp/',
   a: '/otherapp/',
}

These calls will lazy load if not already registered:

$.$('#fooBarController') => /myapp/controllers/foobar.js
$.$('a#fooController') => /otherapp/controllers/foo.js

Right now, if a script fails to load it wont attempt any more loads, though I'd like to figure out a more forgiving approach since mobile devices my loose network connections etc.

Also remember lazy load is blocking so it's still best to eagerly load your main application components and allow the peripheral components to be lazily loaded if they are used.

Id also like to support plug-able loading strategies, and explore how we might actually implement lazy loading with asynchronous strategies.  But leaving those for another day, I'm hoping for user feed back regarding the initial implementation.

Thanks,
Thatcher

--
Christopher Thatcher

Jrad

unread,
Sep 7, 2010, 4:40:55 AM9/7/10
to jquery-claypool
Hi Chris,
I made a try to lazy load scripts and found that the following
environment property works for us:

appbase: 'app/'

I first noticed that, when I set appbase according to your above post
i.e. appbase: {
'': 'app/',
}
claypool tries to fetch an invalid url (something like: http://.../xyz/[object
object]controllers/foo.js). I read your code
and found that appbase is flushed as an object to the folder variable!


On Aug 27, 4:14 pm, chris thatcher <thatcher.christop...@gmail.com>
wrote:

chris thatcher

unread,
Sep 9, 2010, 11:08:24 PM9/9/10
to jquery-...@googlegroups.com
Quite right and thanks for the correction.  What I'm going to do to correct it is inspect the returned value of $.env('appbase').

If its a simple string we'll use that value, and if its an object we will use the current namespace or default namespace.  I'll post this patch asap.

Thatcher

--
You received this message because you are subscribed to the Google Groups "jquery-claypool" group.
To post to this group, send email to jquery-...@googlegroups.com.
To unsubscribe from this group, send email to jquery-claypo...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/jquery-claypool?hl=en.




--
Christopher Thatcher
Reply all
Reply to author
Forward
0 new messages