does CSS Sprite is default ?

48 views
Skip to first unread message

wahaha

unread,
Jan 30, 2012, 9:56:10 PM1/30/12
to Google Web Toolkit
there has many small pictures in a page,does GWT will merge them by
default?

Thomas Broyer

unread,
Jan 31, 2012, 7:12:10 AM1/31/12
to google-we...@googlegroups.com
As I often say: there's no magic.

GWT will only do something if you somehow "tell" it to do it: it won't try to optimize images unless they are in an ImageBundle or ClientBundle.

Note however that the default behavior for ClientBundle is actually not to create a "CSS sprite" but to use data: URIs directly embedded in the JS (and/or in the CSS for a CssResource, which is also embedded as a String in the JS) for all browsers that support it (all but IE6/7, also, IE8 will fallback to loading images from the server –without any optimization at all, IIRC– when using HTTPS, because data: URIs in an HTTPS-served page would result in a "mixed content" warning)

Sebastian Gurin

unread,
Jan 31, 2012, 1:49:06 PM1/31/12
to google-we...@googlegroups.com
If you use gwt client bundle for referencing your images in your gwt app, gwt compiler will decide how is best way of "storing" the images.

By default, it stores small images in with the content embedded in the urls, like: <img src="data:101010010100110". For bigger images, it store them as regular files and regular urls, like src="afile1.png"

In client bundles you can force the gwt compiler to a technic. For example, if I don't want the compiler to "inline" the data image in urls I annotate the ImageResource with @ImageOptions(preventInlining=true) as the following code shows.

import com.google.gwt.core.client.GWT;
import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.ImageResource;
import com.google.gwt.resources.client.ImageResource.ImageOptions;

public interface TestImageResources extends ClientBundle {
TestImageResources INSTANCE = GWT.create(TestImageResources.class);

@ImageOptions(preventInlining=true)
@Source("smallLion.png")
ImageResource smallLion();

}

regards,

> --
> 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.
>


--
Sebastian Gurin <sgu...@softpoint.org>

Reply all
Reply to author
Forward
0 new messages