JavaScript Bundling

1 view
Skip to first unread message

Allahbaksh Asadullah

unread,
Mar 11, 2009, 8:51:41 PM3/11/09
to Google-Web-Tool...@googlegroups.com
Hi,
In most of cases we face situation where there are existing JavaScript library available to do specific job (Example Online Diff). We don't want to write it again but number of HTTP request to get those JavaScript files are some times huge.
Can we bundle javascript or load it as Text Resources and do something with it? Is something of that sort could save lot of HTTPRequest?

Can some one let me know whether the idea of doing this is good or it will not workout properly.
Regards,
Allahbaksh M Asadullah

BobV

unread,
Mar 11, 2009, 9:19:29 PM3/11/09
to Google-Web-Tool...@googlegroups.com
You can use a TextResource from the incubator and dynamically add a
<script> tag to the document.

I suspect that once ClientBundle is integrated into trunk, it would be
worthwhile to talk about a proper JavaScriptResource type.

--
Bob Vawter
Google Web Toolkit Team

Thomas Broyer

unread,
Mar 11, 2009, 9:32:54 PM3/11/09
to Google Web Toolkit Contributors
Two solutions come to mind:
a) use a GWT Linker [1,2] to prepend scripts dependencies (<script/>
in your modules' gwt.xml) to the selection script; the problem is that
the selection script isn't (shouldn't be) cached, so it should remain
as small as possible.
b) use YUI Builder [3] to concatenate (and minify) all your scripts
into a single file; it should be done up-front as it impacts your
<script> tags (in your page and/or your modules)
c) combine both: use a linker to combine the scripts into a single
file.
(yes, that makes three solutions...)

For options b and c, I'd recommend using a <strong name>.cache.js file
name; and you can of course process stylesheets too.

[1] http://code.google.com/docreader/#p=google-web-toolkit-doc-1-5&t=ReleaseNotes_1_5_Compiler
[2] http://google-web-toolkit.googlecode.com/svn/javadoc/1.5/com/google/gwt/core/ext/Linker.html
[3]http://yuilibrary.com/projects/builder

Bruce Johnson

unread,
Mar 12, 2009, 10:58:47 AM3/12/09
to Google-Web-Tool...@googlegroups.com
On Wed, Mar 11, 2009 at 9:32 PM, Thomas Broyer <t.br...@gmail.com> wrote:
a) use a GWT Linker [1,2] to prepend scripts dependencies (<script/>
in your modules' gwt.xml) to the selection script; the problem is that
the selection script isn't (shouldn't be) cached, so it should remain
as small as possible.

It's good to paranoid about the speed of the selection script download, but in practice this probably isn't so bad if you have properly configured HTTP headers. The exact semantics for the selection scripts are "must revalidate" rather than "cannot cache". In other words, an If-Modified-Since request for the selection script should be returning "Not Modified" except when the app is actually redeployed on the server.

Thus, I kinda like (a).


Allahbaksh Asadullah

unread,
Mar 12, 2009, 11:19:50 AM3/12/09
to Google-Web-Tool...@googlegroups.com
Hi,
As I have too many JavaScript file and most of them are static and are in Apache or BSD licence. So it doesnot make any difference if I combine all the JavaScript into a single file. Is it a recommended way? Using GWT Linker as Bruce and Thomas say is most appropriate way? What are the performance aspects? Are there any plans to have exclusive javascript bundling?
Regards,
allahbaksh

Fushion

unread,
Mar 12, 2009, 5:43:03 PM3/12/09
to Google Web Toolkit Contributors
Watch out for certain JS libraries.
There are libraries that call other sub-libraries or resources (images/
css) by (relative) url.
These wont be easily bundled into a single script!

Regards,
Menno van Gangelen.


On Mar 12, 4:19 pm, Allahbaksh Asadullah <a.allahba...@gmail.com>
wrote:
> Hi,
> As I have too many JavaScript file and most of them are static and are in
> Apache or BSD licence. So it doesnot make any difference if I combine all
> the JavaScript into a single file. Is it a recommended way? Using GWT Linker
> as Bruce and Thomas say is most appropriate way? What are the performance
> aspects? Are there any plans to have exclusive javascript bundling?
> Regards,
> allahbaksh
>
>
>
> On Thu, Mar 12, 2009 at 8:28 PM, Bruce Johnson <br...@google.com> wrote:
Reply all
Reply to author
Forward
0 new messages