Yesod has powerful features for including dynamic scripts, using widgets. In many cases this is exactly what I want, but in some, I want scripts to be loaded globally in all pages.
The primary motivation for globally loaded scripts, appearing in the <head>
element in all pages, is for using something like PJAX, possibly together with
HTML5 custom elements. I'd like to declare a number of custom elements, and
only use HTML markup in the widgets using the custom elements, i.e. no dynamic
script tags added to the page by the widgets. By doing so, the PJAX-variant
could be much simpler, not having to inject scripts in the page sent in the
PJAX response. All custom elements' Javascript would already be loaded, and the
DOM insertions of the widget markup would trigger the scripts to run.
A complication with these global scripts are that all possibly needed scripts have to be loaded. For this to be statically known, at compile-time, the globally loaded scripts need to represented in types somehow. This demonstration is a dumbed down version of Yesod, just to illustrate the design, and some machinery for associating global scripts with an application (Foundation type).