2009年1月3日星期六

Re: [fw-mvc] Zend Dojo Form and network usage efficiency

-- Jiří Helmich <jiri@helmich.cz> wrote
(on Saturday, 03 January 2009, 11:38 AM +0100):
> I'm using Zend_Dojo_Form and I realized that there is an imperfection in the
> whole mechanism. It appears when a client has a long ping to server. When using
> Dojo, browser has to download many small "uncompressed" (trailing white-space,
> etc.) external JavaScript files which takes such a long time. For expamle,
> there are almost 40 JS files appended to a login page with 4 Dojo elements
> (textbox, pwtextbox, filtering select, submit button).
>
> The idea is – the Dojo view helper has to know which files have to be appended
> to processed HTML output, so why don't we put them all together (and maybe
> cache them) into one bigger external JavaScript file (which can be disengaged
> from trailing whitespace) and append only this one JavaScript file.  It would
> decrease the number of connections to the server which is as Google presented
> on its Dev Days in Prague the most important thing nowadays.
>
> Am I right or there is a huge mistake in my theory? Has somebody started to
> work on something similar already?

What you're describing is two-fold, though you may not be aware of it.
One part is complete, the other is planned.

The first part is accomplished already via the Dojo build system, which
allows you to create a "build profile" that specifies all the
dependencies for a particular application or application layer:

http://dojotoolkit.org/book/dojo-book-0-9/part-4-meta-dojo/package-system-and-custom-builds

The build system compiles all these dependencies into a single file,
stripping whitespace and performing a number of heuristics to condense
the code, and also interning all template files. (It can also condense
CSS themes into single files, btw, saving even more bandwidth and
eliminating requests to the server.) The functionality for doing this is
available in a source build of Dojo, which is what we ship in our full
distribution. I've I've blogged a bit about using builds with ZF before:

http://weierophinney.net/matthew/archives/188-Proper-Layer-files-when-using-Dojo-with-Zend-Framework.html

Unfortunately, it means doing a little extra work when you use ZF to
generate your Dojo interfaces -- you need to look through your pages and
determine which dojo.require statements are being generated, compile the
list, build your profile, etc.

Which brings us to the second part of what you describe: automating the
process of compiling the list of dependencies. I've done some
preliminary work on this, and will be trying to have a proposal up this
coming week. The basic idea is to generate a specialized logger that
would write 1) a layer file, and 2) a build profile based on that layer
file. It would then be up to the developer to actually generate the
custom build -- likely from your deployment script.

--
Matthew Weier O'Phinney
Software Architect | matthew@zend.com
Zend Framework | http://framework.zend.com/

没有评论: