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