AmaltasCoder
AmaltasCoder

Reputation: 1123

Enable Google App Engine Java to serve webp images when the client accepts them

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.

Upvotes: 0

Views: 212

Answers (1)

isk
isk

Reputation: 21

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

Upvotes: 0

Related Questions