gzippen all gwt output files?

416 views
Skip to first unread message

Ed

unread,
Dec 22, 2010, 10:42:54 AM12/22/10
to Google Web Toolkit
I like to know how others gzip their gwt output files
I think you have the following options:
1) Let the webserver (in my case apache) zip all gwt files by using
mod_deflate (or mod_gzip) , just before they are send.
2) Gzip them yourself during the build and set the correct headers in
your webserver config (through mod_headers).

Option 1) is easy.
Option 2) might give some advantage, because you only have to gzip all
files once, but costs some extra work after gwt compilation and Header
configuraiton in you webserver.

Sooo, is it worth going for option 2) ?

Thomas Broyer

unread,
Dec 22, 2010, 11:37:50 AM12/22/10
to google-we...@googlegroups.com
3) add <inherits name="com.google.gwt.precompress.Precompress"/> to your gwt.xml and the GWT compilation will automatically GZip all emitted *.html, *.js and *.css (by default) as additional (by default) *.gz files; so you only have to have MultiViews enabled in Apache (or a similar setup that serves the *.gz file if it exists and the client accepts gzip encoded responses). Note that the DefaultServlet in Jetty (6 and 7) already does this, and it's turned on by default: http://jetty.codehaus.org/jetty/jetty-6/apidocs/org/mortbay/jetty/servlet/DefaultServlet.html & http://download.eclipse.org/jetty/stable-7/apidocs/org/eclipse/jetty/servlet/DefaultServlet.html
It's similar to your option 2) but without the "extra work after gwt compilation" (and possibly without the extra configuration, depending on your server).

Ed

unread,
Dec 22, 2010, 12:13:37 PM12/22/10
to Google Web Toolkit
Cool Thomas, didn't know that...
Are their things about gwt you don't know ? :)...you keep suprising
me.....
Thanks a lot...
I will have a look hot this works with the "MultiViews" in apache...

Ed

unread,
Dec 23, 2010, 9:28:03 AM12/23/10
to Google Web Toolkit
I am using the PreCompress linker now, but have problems
precompressing my xml files.
I added this line:
<extend-configuration-property name='precompress.path.regexes'
value='.*\.xml' />

As I want it to compress my static XML cms files, but it doesn't
compress them.
Might this because it only compress generated files ?...

My static content is located in the war dir and I use the maven gwt
plugin for gwt compilation.

Thomas Broyer

unread,
Dec 23, 2010, 9:41:07 AM12/23/10
to google-we...@googlegroups.com
Yes, only "generated" files are compressed (this includes static resources though, as long as they come from a "public path" in a compiled GWT module, i.e. a theme's CSS).

Ed

unread,
Dec 23, 2010, 3:25:16 PM12/23/10
to Google Web Toolkit
Where do you put your static (not gwt) resources (css/images/js not
part of clientbundles) ?

I like putting them in the war folder (war/resources) and thought the
public folder usage was a bit deprecated :(

Thomas Broyer

unread,
Dec 23, 2010, 4:17:19 PM12/23/10
to google-we...@googlegroups.com
The public path allows for reuse (as for themes). In that sense, its not deprecate.
Otherwise, yes, you'll put them in the "war", but then you're responsible for them (and thus for compressing them)

Ed Bras

unread,
Dec 23, 2010, 5:16:49 PM12/23/10
to google-we...@googlegroups.com
Thanks,
I used to the public folder in the past but didn't like it in reusable components as you always got the public resources in your project when using the reusable component, even if you didn't use or want them :(...
Where do you put your static resources ?

Another thing: 
I am not sure if MultiViews it the way to use it on Apache as MultiViews is used for language negotiation (as I understand it) and means that the requested file should "not" be present, but it should be present with an extension.

For example:
Request: bla.nocache.js
the file bla.nocache.js is not allowed to be present on the server. If this file is present, it will not look for any better (gz) version, and directly return this file.
What should be present for example:
bla.nocache.js.en
bla.nocache.js.gz.en

Then it will return the file that best meets the browser properties, such that it will return "bla.nocache.js.gz.en".

I got this working with the following config for a directory section in Apache:
 Options +MultiViews
 AddEncoding x-gzip .gz .tgz
 AddLanguage en .en

But that means that I have to rename all files to have a language extension :(.. Which is not really the path I want to go in to.
Do I overlook something, or is this really the way to go?


Ed

unread,
Dec 23, 2010, 6:30:38 PM12/23/10
to Google Web Toolkit
Did some more reading and trial and error and have it now working as
followed:

1) In Apache config file:
a):
<Directory "YOUR GWT DIR" >
Options +MultiViews
AddEncoding x-gzip .gz .tgz
</Directory>

b):
<FilesMatch "\..js.gz$">
ForceType text/javascript
</FilesMatch>

2) Remove all original not-gzipped files such that content negotiation
occurs.

If you remove b) (which I would like) it doesn't work as the Content-
Type that the browser receives of a js.gz will be application/x-gzip
which is wrong as it must be text/javascript, otherwise it doesnt
work. Config snippet b) will force this.
I would suppose that b) isn't necessary and that Apache would discover
and set this them self... but it didn't...

So the question now: is this the way to do it??
My complain: I have to add b) snippets for every content type that is
gzipped: css, js, xml, html, etc.. That seem awkward...

Example of request and response headers:
-----
Response Headersview source
Date Thu, 23 Dec 2010 23:20:38 GMT
Server Apache/2.2.6 (Win32)
Content-Location login.nocache.js.gz
Vary negotiate
TCN choice
Last-Modified Thu, 23 Dec 2010 20:35:17 GMT
Accept-Ranges bytes
Content-Length 2339
Cache-Control public, max-age=0, must-revalidate
Expires Thu, 23 Dec 2010 23:20:38 GMT
Content-Type text/javascript
Content-Encoding gzip


Request Headersview source
Host localhost
User-Agent Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:
1.9.1.16) Gecko/20101130 Firefox/3.5.16
Accept */*
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip,deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive 300
Connection keep-alive
Referer http://localhost/bv-web/
If-Modified-Since Thu, 23 Dec 2010 20:35:17 GMT
Cache-Control max-age=0

Ed

unread,
Dec 23, 2010, 7:14:20 PM12/23/10
to Google Web Toolkit
OK :(

Couldn't let it rest...
Found out that the above b) snippet isn't necessary, but was because I
had somewhere in my apache config the following line that spoiled it:
AddType application/x-gzip .gz .tgz
So every file returned with .gz as extension got automatically this
content type back which was incorrect

Bottom line:
1) Remove all not gzipped files otherwise apache will not perform any
content negotiation and simple returns the unzipped file.
2) Add the following lines to your apache config (in a Directory/Files/
Location directive if you whish):
Options +MultiViews
AddEncoding x-gzip .gz

And that's it...
Because all the modern browsers support gzip, it's safe to remove the
original unzipped files.

Now I still have to find out how to gzip my remaining static
resources...
Thomas: how do you that ? and where you put your static resources?


Thomas Broyer

unread,
Dec 24, 2010, 4:36:57 AM12/24/10
to google-we...@googlegroups.com
I don't do it actually ;-)
(I only have an image and 2 JSPs –login page and GWT app host page–, we'll probably add a CSS later, but browsers will likely only download it once and then only check for freshness/staleness of their cache, so we'll probably won't gzip it; and it'll be quite small moreover)

And I put my static resources in my "war" (src/main/webapp actually, we're using Maven).

Two more small things:
 - in Apache, you could use mod_rewrite instead of MultiViews (a search on Google lead me to Drupal which seems to be doing just this), either to send the appropriate gzip/non-gzip file if you keep both, or in combination with mod_deflate's INFLATE filter if you only keep the gzipped file (using mod_filter).
 - you can <set-configuration-property name="precompress.leave.originals" value="false" /> in you *.gwt.xml to have the GWT Compiler only output the gzipped files.

Ed Bras

unread,
Dec 24, 2010, 7:23:06 AM12/24/10
to google-we...@googlegroups.com
Thanks for the tip.
I did look at the rewrite option, but not so font of the rewrite modules, very powerful do.
I wasn't aware of the mod_filer combi with mod_deflate. I like that one, very simple:
FilterDeclare gzip CONTENT_SET
FilterProvider gzip inflate req=Accept-Encoding !$gzip
FilterChain gzip

I like the idea: mostly the browser do support gzip anyway, just for those stoneage browsers, you simple inflate the gzip just before sending it... 
That's better then the other way around: zipping when they support gzip (as they almost always do).

BTW: I think I am going to put my static stuff in the public folder, such that I use the precompressor power and some other benefits... These aren't resusable components anyway (application endpoints), so that's ok if you ask me..

BTW: I am running in noserver mode, so I have 2 deployment deliverables: war and gzip file for Apache. So all my static stuff is located under Apache.
BTW: you could cache your css file infinte just like the gwt cache files policy if you let maven add a version/build number on a new build (just like gwt does with his md5 files), such that your css files are always unique... Yahoo does this as well, and it's easy done: rename the css and replace the css link....


--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

Ed Bras

unread,
Dec 24, 2010, 1:41:34 PM12/24/10
to google-we...@googlegroups.com
It works really nice now:
put all the content in the several Public folder: general public folder and specific Public folder as I have several gwt app's that share some general stuff.
It's bit of puzzling to output and move all files in the correct directories but it's worth doing so as all files are now gzipped which is a big win for me as I have quite a bit of CMS published xml files that I load lazily. These files are now automatically compressed during gwt build.
Example: a xml file of 100K is now about 15K, which is nice of course...
I can advice everybody to do this... :)

shashi kant pandey

unread,
Dec 24, 2010, 7:30:36 AM12/24/10
to google-we...@googlegroups.com
 Go to the proprieties and click the change batten and after that change the application which is related to you file and you will open your file
for quire contact me shashi   

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.




--
https://mail.google.com/mail/c/photos/public/AIbEiAIAAABECO2Ijfq8p-H55gEiC3ZjYXJkX3Bob3RvKihhYTViMTRlMjM5ODExNTZkZDg2MmM1YTI5MzA3NTUyNGM4ZGVlY2JmMAGXnNjszH_f7DgHVPA5NcrcN9NUow

balachandra maddina

unread,
Dec 29, 2010, 5:34:51 AM12/29/10
to google-we...@googlegroups.com
Im using GWT 2.0.3. and when add the <inherits name="com.google.gwt.precompress.Precompress"/> im getting 

[ERROR] Unable to find 'com/google/gwt/precompress/Precompress.gwt.xml' on your classpath;

Regards,
bala.

On Wed, Dec 22, 2010 at 10:07 PM, Thomas Broyer <t.br...@gmail.com> wrote:
3) add <inherits name="com.google.gwt.precompress.Precompress"/> to your gwt.xml and the GWT compilation will automatically GZip all emitted *.html, *.js and *.css (by default) as additional (by default) *.gz files; so you only have to have MultiViews enabled in Apache (or a similar setup that serves the *.gz file if it exists and the client accepts gzip encoded responses). Note that the DefaultServlet in Jetty (6 and 7) already does this, and it's turned on by default: http://jetty.codehaus.org/jetty/jetty-6/apidocs/org/mortbay/jetty/servlet/DefaultServlet.html & http://download.eclipse.org/jetty/stable-7/apidocs/org/eclipse/jetty/servlet/DefaultServlet.html
It's similar to your option 2) but without the "extra work after gwt compilation" (and possibly without the extra configuration, depending on your server).

--

Ed Bras

unread,
Dec 29, 2010, 9:52:57 AM12/29/10
to google-we...@googlegroups.com
It's a new feature in 2.1.0, as such not present in 2.0 yet... 
Please upgrade to 2.1.0
Reply all
Reply to author
Forward
0 new messages