Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 7 Next »

Issue 1277

Background

Sometimes, complex gadgets may want to load code incrementally and have that code be available to all new and existing views of a gadget without having to re-parse the needed code each time a view renders.  Giving a gadget an execution scope in which to load script can significantly improve performance of a complex gadget, or any gadget that opens views frequently.

This would also apply to the incremental loading of other resources.

It should be noted that setting up an alternate channel for eventing is strongly discouraged here, even though it would be possible.  The end result would likely be a degradation of user experience in the container in the long run.  If eventing APIs are seen as insufficient, it would be better to get involved and make your concerns heard rather than work around the problem permanently.

Details

To use this feature, a gadget must require(or optional) the feature like so:

  <Optional feature="shared-script-frame">
    <Param name="view">script</Param>
  </Optional>

Gadgets MUST specify a param named "view" that indicates which gadget view should be rendered as the script frame.  This specified view will render hidden on the page.

The container SHOULD render this gadget view before any other view of the gadget is rendered.  In other words, the script frame view of a gadget SHOULD always be the first view to render in a container page. If all instances of a gadget are removed from the page, it is up to the container if the last remaining script frame view is also removed, or if it will persist to save state in case another view is rendered in the future.

The container MUST only create 1 rendering of the shared script frame view at any given time.  If the container sandboxes gadgets in a way to isolate their execution scope, it should be done in a way so that every gadget instance (of this same gadget) requesting this feature would be able to (in terms of browser security) access the contents of any other instance (of this same gadget).

Gadgets can request a reference to the shared script frame:

  gadgets.util.registerOnLoadHandler(function() {
    gadgets.script.getScriptFrame(function(scriptFrame) {
      // Do something with the script frame here.
    };
  });
  • No labels