concept widget in category javascript

appears as: Widgets, widget, widget, The widget
Third-Party JavaScript

This is an excerpt from Manning's book Third-Party JavaScript.

Figure 1.3. An example commenting section on a publisher’s website, powered by the Disqus commenting widget

Disqus is an example of a product that’s only usable in its distributed form; you’ll need to visit a publisher’s page to use it. But widgets aren’t always standalone products like this. Often they’re “portable” extensions of larger, more traditional stay-at-home web applications.

  • Flexibility— If you ever want to change the dimensions of the widget, you’ll be out of luck. Since the iframe dimensions are fixed on the iframe element on the parent page, and those attributes can’t be modified from content loaded inside the iframe, there’s no way to dynamically resize the widget.
  • Aesthetics— The look and feel of the widget will need to be completely independent of the parent page’s styles. The widget won’t be able to inherit basic styles, like font family, size, or color.
  • Interaction— Will the widget need to read or modify the publisher’s DOM? What if the publisher needs to interact with the contents of the widget? Could multiple instances of the widget communicate with each other? None of these are possible with static iframes.
  • Reporting— Did the browser user actually view the widget? How much time did they spend on the page before viewing it? Retrieving this and other valuable statistics requires JavaScript running on the publisher’s page.