2

I have a lot mouseover images on my GAE development (Java). I hosted it at appspot.com. The current cache-control header I got = no-cache, re-validation. So, when the image hovered and mouse out , it will reload the image and then this is where latency comes...

I am not sure how to deal with this. Any help please (Java solution)?

Edited ==>

appengine.xml

<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
    <application>s~xxxxxx</application>

    <version>1</version>

    <static-files>
        <include path="/images/**" expiration="1d" />
        <include path="/scripts/**" expiration="1d" />
        <include path="/stylesheets/**" expiration="1d" />
        <include path="/*.p12" expiration="1d" />
        <include path="/favicon.ico" expiration="1d" />
    </static-files>

    <threadsafe>true</threadsafe>

    <warmup-requests-enabled>true</warmup-requests-enabled>

    <system-properties>
        <property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
    </system-properties>

    <sessions-enabled>true</sessions-enabled>
</appengine-web-app>

When the first load the image (http://xxx.appspot.com/images/myicon.png) after deployment, I will get something like this. There are 2 cache-controls... I guess "no-cache" cache-control replaced the earlier private cache-control.

Response Header1

But then if I refresh that page again, it will go back http 1.1 304 Not Modified.

Response Header2

lannyboy
  • 617
  • 1
  • 10
  • 20

4 Answers4

5

If you sign in as an administrator, app engine will try to suppress the cache behavior. Can you try it with logging out, or another account?

Here is a relevant issue: http://code.google.com/p/googleappengine/issues/detail?id=8509

Takashi Matsuo
  • 3,406
  • 16
  • 25
  • Can you share the actual link for one of those image? I'll check the response. My e-mail address is matsuo.takashi@gmail.com. – Takashi Matsuo Mar 05 '13 at 07:19
  • what if the administrators want this feature available? i have a lot of domain admins (for google usage) that actually run this GAE website, so you're telling me mouseover and mouseout are not actually a good idea for GAE UI design? – lannyboy Mar 05 '13 at 07:20
  • Takashi, I appreciate with your help. But the GAE website that I host is inside my private domain (paid) and not public one. – lannyboy Mar 05 '13 at 07:21
  • I just sent an email to you. Thanks! – lannyboy Mar 05 '13 at 07:26
  • If you experience it with non-admin account, it's a bug. Please file a bug on our issue tracker. If you want app engine not to suppress the cache behavior, please file a feature request. Here are some workarounds; maybe you can have another account only for app engine app (different from the account you're nomally using), or you can pre-fetch those images when the page loaded. – Takashi Matsuo Mar 05 '13 at 07:27
  • I have pre-loaded images in my Javascript, but then they are not cached to the Google Chrome browser. This does not happen when I run my development at my localhost. It happens only when deployed to appspot.com – lannyboy Mar 05 '13 at 07:33
  • Takashi, may I know where can I report this bug? – lannyboy Mar 05 '13 at 07:36
  • So, isn't it a javascript question? For the cache header part, isn't it clear with my answer? If so, can you accept this answer and open a new question about your javascript caching code? – Takashi Matsuo Mar 05 '13 at 07:36
  • Also, I think your company is our premier customer, so that you should be able to consult our support engineers. Have you considered to do so? – Takashi Matsuo Mar 05 '13 at 07:39
  • I am just a programmer, I didn't know much of that. May be I can check with the administrator. Anyway, really thank with your helps. – lannyboy Mar 05 '13 at 07:40
  • Oh I am using GAE SDK 1.7.4, there is a newer one, let me try that one first before I submit the bug ticket. – lannyboy Mar 05 '13 at 07:41
  • After tried GAE SDK 1.7.5, it is still the same... I will straight away report it as a bug. – lannyboy Mar 05 '13 at 10:06
  • Hi Takashi, I read your blog post article, thanks. But I don't understan why you put robots.txt in the cache (unless you have static content, a website needs to be always up to date with its page links). So I was wondering if you has issues of crawlers coming every hour? – Zied Hamdi Dec 05 '13 at 08:43
1

I also had some issues configuring browser caching and defining Expires headers on static files with Google App Engine for Java. The problem was that a filter-mapping in web.xml overruled the configuration of static files. I documented the issue and solution here: How to set Expires headers on static files with Google App Engine. It might be interesting to check or share your web.xml file.

0

Does it have to be a Java solution? How about a pure CSS solution that avoids web requests and latency (after the first request)? If you put all of your rollover images together into a single image and put the coordinates of each rollover image (sprite) into CSS, you will see the images as fast as the browser can display them, almost instantly.

Here are some links to information on sprites:

The last link uses this example CSS:

#logo-link
{
width:191px;
height:151px;
text-decoration:none;
display:block;
background-image:url(dw-logo-sprite.jpg);
background-position:191px 0;
}
#logo-link:hover,#logo-link:active  { background-position:0 0; }

Basically, you declare the image's URL once in CSS and include the geometry of the first sprite. On hover, it changes the geometry to use the second sprite (of the same image).

Brent Washburne
  • 12,904
  • 4
  • 60
  • 82
0

If you want to serve an image from a servlet for some reason, then you can set the cache-control response header like this with Jersey:

@GET
@Path("/{url}/{maxHeight}")
@Produces("image/jpeg")
public Response view(
        @Context HttpServletRequest req,
        @PathParam("url") String url,
        @PathParam("maxHeight") int maxHeight
) throws IOException, URISyntaxException {
    ... [code to generate imageData]
    return Response
            .ok(imageData)
            .cacheControl(CacheControl.valueOf("max-age=2592000"))
            .build();
}

```

matt burns
  • 24,742
  • 13
  • 105
  • 107