0

I have a Google Appengine Java application that I use to host a simple static website.

My .html, .css, .jpg files go in the war directory. Here's my web.xml

<?xml version="1.0" encoding="utf-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>
</web-app>

Here's my appengine-web.xml

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

  <!--
    Allows App Engine to send multiple requests to one instance in parallel:
  -->
  <threadsafe>true</threadsafe>

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

  <static-files>
    <include path="/**.png" expiration="7d" />
    <include path="/**.gif" expiration="7d" />
    <include path="/**.jpg" expiration="7d" />
    <include path="/**.jpeg" expiration="7d" />
    <include path="/**.tif" expiration="7d" />
    <include path="/**.tiff" expiration="7d" />

    <include path="/**.svg" expiration="7d" />
    <include path="/**.eot" expiration="7d" />
    <include path="/**.ttf" expiration="7d" />
    <include path="/**.woff" expiration="7d" />

    <include path="/**.webp" />

    <include path="/**.ico" />
    <include path="/**.html" />
    <include path="/**.css" />
    <include path="/**.js" />
    <include path="/**.zip" />
    <include path="/**.msi" />    
    <include path="/**.exe" />    
    <include path="/**.xml" />    
    <include path="/**.txt" />    
    <include path="/**.htc" />
  </static-files>

</appengine-web-app>

I would like to do serve webp version of images whenever possible. How can I do this?

I conducted a simple experiment. I have file.jpg and corresponding file.webp in my war directory. I have a home.html page that refers to file.jpg. When I access home.html on Google Chrome -- the jpg is served not the webp.

AmaltasCoder
  • 1,123
  • 3
  • 17
  • 35
  • hm, can you remind why Google Chrome must lost different image at this case? – Igor Artamonov Jun 30 '16 at 09:10
  • @IgorArtamonov webp images tend to be smaller than corresponding jpegs, this can significantly reduce load times of a page. This is probably one of the major reasons that google got behind webp in the first place -- faster internet. Google Chrome and Opera are the only major browsers that support webp at this point of time. When Chrome asks for an image from a server it sends an accept header stating that it can accept a webp. – AmaltasCoder Jun 30 '16 at 10:31
  • sorry, _lost_ -> _load_ in my previous comment – Igor Artamonov Jun 30 '16 at 10:33
  • I'm asking why it should load different url? You have url `/images/image.jpg` in your html, right? How chrome should figure out that this image url is invalid and it must be using `/images/image.webp` instead? – Igor Artamonov Jun 30 '16 at 10:35
  • https://www.maxcdn.com/blog/how-to-reduce-image-size-with-webp-automagically/ – AmaltasCoder Jun 30 '16 at 10:42
  • First, I am not clear of the whole thing. But the article above suggests that using the Accept: image/webp header the server can figure out that the client can instead accept a corresponding image.webp – AmaltasCoder Jun 30 '16 at 10:44
  • yes, server can figure it out, but you have to write this server side code that will serve different image, based on _Accept_ header – Igor Artamonov Jun 30 '16 at 11:12
  • It's a common use case, I thought there might be an existing way (some appengine-web.xml setting maybe) in App Engine to do it. – AmaltasCoder Jun 30 '16 at 11:29
  • no, afaik app engine doesn't have this feature – Igor Artamonov Jun 30 '16 at 11:30

1 Answers1

0

If you can change JavaScript code, it'll be easier to do it there: https://developers.google.com/speed/webp/faq#how_can_i_detect_browser_support_for_webp

isk
  • 21
  • 3