There are a number of enhancements/bug fixes from this refactor relating to builds:
Reduce CPU used at page load time by precompiling templates at build time.
Make sure that dependencies specified in templates via the requires="..." attribute
are properly included into the build.
Builds with templates no longer download requirejs-text/text.js, delite/Template.js,
and delite/handlebars.js to the browser. That's assuming that you do a custom build
(rather than using the delite/layer.js file), and assuming that the builder and loader
are working correctly. We could also consider excluding handlebars.js and Template.js
from the delite/layer.js file.
Also one bug fix for the non-build case: stop using the text! plugin directly since
the parentRequire() method passed to load() runs in the context of the caller. If the
caller remapped requirejs-text/text to point to another module, it would inadvertently
affect the behavior of delite/handlebars.
Previously, the build step for handlebars!foo.html would merely write this to the layer file:
Thus the build eliminated the XHR to get the template text, but still ran template compilation
at page load, and the browser still needed to download delite/handlebars.js, and therefore also
requirejs-text/text.js and delite/Template.js.
With this commit, the handlebars build writes the generated template function to the layer,
for example:
Note that this increases the bytes needed for each template. For example, deliteful's layer.js goes
from 112351 bytes / 26393 gzipped to 127540 bytes / 28103 gzipped. But on the other hand, it means
that Template.js doesn't need to be downloaded to the browser, a savings of 9536 bytes (3230 gzipped).
You don't currently get that savings though if you include delite/layer.js, since delite/layer.js
currently includes Template.js and handlebars.js.
Refactor how handlebars plugin works in builds.
There are a number of enhancements/bug fixes from this refactor relating to builds:
requires="..."
attribute are properly included into the build.requirejs-text/text.js
,delite/Template.js
, anddelite/handlebars.js
to the browser. That's assuming that you do a custom build (rather than using thedelite/layer.js
file), and assuming that the builder and loader are working correctly. We could also consider excludinghandlebars.js
andTemplate.js
from the delite/layer.js file.Also one bug fix for the non-build case: stop using the
text!
plugin directly since theparentRequire()
method passed toload()
runs in the context of the caller. If the caller remappedrequirejs-text/text
to point to another module, it would inadvertently affect the behavior ofdelite/handlebars
.Previously, the build step for
handlebars!foo.html
would merely write this to the layer file:Thus the build eliminated the XHR to get the template text, but still ran template compilation at page load, and the browser still needed to download
delite/handlebars.js
, and therefore alsorequirejs-text/text.js
anddelite/Template.js
.With this commit, the handlebars build writes the generated template function to the layer, for example:
Note that this increases the bytes needed for each template. For example, deliteful's
layer.js
goes from 112351 bytes / 26393 gzipped to 127540 bytes / 28103 gzipped. But on the other hand, it means that Template.js doesn't need to be downloaded to the browser, a savings of 9536 bytes (3230 gzipped). You don't currently get that savings though if you includedelite/layer.js
, sincedelite/layer.js
currently includesTemplate.js
andhandlebars.js
.PR in #431.