Force image caching in gallery

6 views
Skip to first unread message

dicko

unread,
Nov 10, 2009, 8:55:47 PM11/10/09
to Google Web Toolkit
Hi there

I've setup a basic GWT app that's essentially an image gallery. The
gallery works by updating an Image widget with widget.setURL('url')
either by clicking a forward or back button. To reduce bandwidth, the
images are only loaded as they're requested (ie. by clicking the
forward button).

However, images are being forcibly reloaded when a use clicks the back
button rather than retrieving a cached image stored by the client's
browser. Obviously, in an attempt to speed the page load and reduce
bandwidth, it would be preferable to use a cached image rather than
reloading the same image every time it's requested.

Has anybody else had this problem and is there any way around this?

Nicolas Wetzel

unread,
Nov 12, 2009, 12:50:48 PM11/12/09
to google-we...@googlegroups.com
Hi,
I've done something like this for www.awdio.com gallery. If the behavior of this gallery is what you're looking for,  i can send you the gwt code. Just send me a email
Nicolas


--

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



Sripathi Krishnan

unread,
Nov 14, 2009, 7:00:27 AM11/14/09
to google-we...@googlegroups.com
Are the images dynamic (user can upload them), or static (known at compile time)?

If the images are from a fixed set of images that are available at compile time, you should consider using ImageBundle. It would take care of most of your concerns. In addition, it can bundle multiple images in a single file, saving further http round trips.

If you are images are dynamic, or if you are not using GWT 2.0, you will have to set appropriate HTTP Cache headers when the image is served. Essentially, your server tells the browser "This image is not going to change for the next few years, so you can cache it till then without bothering to ask me if it has changed".

A typical strategy is assigning every image a unique name based on a MD5 hash of its contents. You then set a far in the future expiry date on that image, so that browser doesn't go back to the server to see if it has changed. If the image changes, you will generate a totally different file name, and hence the browser will download it again.

--Sri


2009/11/11 dicko <d...@mothdesign.com.au>

Vasily Vasilkov

unread,
Nov 14, 2009, 9:48:59 AM11/14/09
to google-we...@googlegroups.com
If you are images are dynamic, or if you are not using GWT 2.0, you will have to set appropriate HTTP Cache headers when the image is served.
 
Could you please clarify - what feature I can use in GWT 2.0 instead of setting http headers?

Sripathi Krishnan

unread,
Nov 14, 2009, 9:11:35 PM11/14/09
to google-we...@googlegroups.com
Sorry - I made a slightly incorrect statement. GWT 2.0 doesn't eliminate the need to set HTTP cache headers.

If you use ImageBundle (http://code.google.com/p/google-web-toolkit/wiki/ImageBundleDesign), GWT will bundle multiple images into a single composite image. Also, if your browser supports it, it can inline images using the data:uri format. As a result, the browser is going to make fewer HTTP requests to the server, and on supported browsers - it may not have to make separate requests because the image is already inlined. But you are still going to benefit by setting appropriate cache headers.

--Sri


2009/11/14 Vasily Vasilkov <chand...@gmail.com>
If you are images are dynamic, or if you are not using GWT 2.0, you will have to set appropriate HTTP Cache headers when the image is served.
 
Could you please clarify - what feature I can use in GWT 2.0 instead of setting http headers?

--

Reply all
Reply to author
Forward
0 new messages