Hey Nico,

Thanks for making this suggestion.
I really like the general idea & think we're on the right path.

Just a couple of questions/suggestions:

1)
> $(window).on('click', ".sakai_add_content_overlay", initialize);


Doing this is basically doing a .live() written with an .on() [1].
We have a pretty heavy DOM atm and this would mean that all those click events 
will have to bubble up to the top.
Since it probably needs to be globally available, I'm not sure whether there is 
an easy fix for it.

Apart from that, doing a $(window).on('click' ... probably doesn't work in IE8 
[2]
Instead (if we really need it), it would be better to do $(document).on('click' 
...)

It would be good to test the lazy loading in IE8/9.

2)
> "events": ["init.newaddcontent.sakai"],
> "selectors": [".sakai_add_content_overlay"],


Doing this feels a bit like duplicating behavior, wouldn't it be good to stick 
with one or the other?
I would recommend going for 'events'.
If not, it would probably be good to use the widget id in the selector (e.g. 
'.sakai_newaddcontent_overlay')

3) We should make sure the Unit tests are still passing for the widget 
configuration.
We'll just need to add the 'trigger' property and note that it will be an 
object.
Currently there is a PR standing open to fix the current tests [3].


- Christian

[1] https://jira.sakaiproject.org/browse/SAKIII-5542
http://bitovi.com/blog/2011/04/why-you-should-never-use-jquery-live.html
http://paulirish.com/2010/on-jquery-live/

[2] 
https://github.com/sakaiproject/3akai-ux/commit/2d19840600a27725a262116dd09b28f0ce83349a#L0R1577
http://stackoverflow.com/questions/4820863/window-click-in-ie-doesnt-work
http://www.quirksmode.org/dom/events/click.html

[3] https://github.com/sakaiproject/3akai-ux/pull/2179/files


On Jun 26, 2012, at 8:21 AM, Nicolaas Matthijs wrote:

> Hi everyone,
> 
> I'm ready to submit a pull request that will allow us to lazy load  
> widgets. However, before doing so, I wanted to ask the list how they  
> feel about the way in which this has been implemented, as it has not  
> been the most straightforward thing to do.
> 
> I've extended the widget configs to have the following property:
> 
> "trigger": {
>       "events": ["init.newaddcontent.sakai"],
>       "selectors": [".sakai_add_content_overlay"],
>       "onLoad": false
> },
> 
> The events property defines an event or list of events the widget will  
> respond to, and the widget will be loaded on the fly when that event  
> is triggered. The selectors property defines a jQuery selector or a  
> list of jQuery selectors the widget will respond to, and the widget  
> will be loaded when elements that match these selectors are clicked.
> 
> The onLoad property, which is a boolean, defines whether or not the  
> widget needs to be included and loaded on page load (for all pages).  
> This allows for the introduction of widgets like "Terms & Conditions"  
> or "Feedback", without having to change all of the core HTML pages.
> 
> Obviously, all of this is optional for a widget.
> 
> Because it's only loading one widget at a time when needed, the added  
> delay is hardly noticeable, even on a slow connection. After that, the  
> widget is present and there is no delay at all. That'll become even  
> more valuable once we move to a single page app implementation.
> 
> The downside is that inside of the widget, the widget itself is still  
> binding to the events and selectors as well:
> 
> $(window).on('init.newaddcontent.sakai', initialize);
> $(window).on('click', ".sakai_add_content_overlay", initialize);
> 
> This is necessary as the widget determines what it needs to call, but  
> it does mean there can be a tiny amount of duplication.
> 
> 
> Doing this lazy loading allows us to cut the number of requests on a  
> typical non-cached page load down from 100+ to about 35 and removes  
> all of the background widgets out of topnavigation. Once cached, this  
> still saves us a big non-cached POST request (120KB) which reduces  
> page load time significantly on a slow connection.
> 
> Kind regards,
> Nicolaas
> _______________________________________________
> oae-dev mailing list
> [email protected]
> http://collab.sakaiproject.org/mailman/listinfo/oae-dev

_______________________________________________
oae-dev mailing list
[email protected]
http://collab.sakaiproject.org/mailman/listinfo/oae-dev

Reply via email to