appengine-silver-120x30.gifThere are a lot of questions about serving static files in the development edition of google app engine. There are also a few answers, but none of them gave me a clear solution. Therefore I decided to look for one myself. In the end I have created a sub-optimal solution that works for me. So maybe it can work for you as well.

Read on to find out what I did.

Google app engine uses the concept of static files. This is a performance optimization. Using the file appengine-web.xml you can configure the way google handles static files. You can include and exclude certain files using their extension or name. More information can be found here at google. This all works nice in the online version, however there seems to be a problem with the development server. Some solutions try to configure the local version as well, still that did not work for me. I decided to look for a servlet that serves static files. Yes it can be that easy.

Check the following post serving static content using a servlet. This post gives you a servlet implementation to serve static files. I used the StaticServlet.java, read the post for more information. Adding this servlet to your web.xml solves the problems in your local environment.

    <servlet>
        <servlet-name>default</servlet-name>
        <servlet-class>org.yourscrum.web.StaticServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    
    <servlet-mapping> 
        <servlet-name>default</servlet-name> 
        <url-pattern>*.png,*.jpg,*.css,*.js</url-pattern> 
    </servlet-mapping>

That is it, now you can test your stuff locally and all your scripts, images, styles are loaded by your application. Of course you have to remove this servlet before uploading your application.

Hope it helps people with their local debugging of jquery scripts or other javascript things. Speaking about jquery, the next post will be about a component used for sorting items using the jquery ui component. I had an issue adding an image to the items in the sortable component.

Serving static files in Google app engine development edition
Tagged on:

3 thoughts on “Serving static files in Google app engine development edition

  • July 8, 2009 at 8:57 am
    Permalink

    Sorry. index.html is:

      [head]
    	[meta http-equiv="refresh" content="0;URL=/Main" /]
      [/head]
    

    Is seems that if you don’t call an static welcome-file, the development-environment can’t find any static-file. If you do call a static welcome-file, it can find any static-file. So, calling a static welcome-file that redirects to the servlet, makes alle static-files available. This wil work in de production-environment too.

  • July 7, 2009 at 9:53 pm
    Permalink

    You can make the index.html-file the welcome-file in web.xml.

    Make the content of the index.html:

    Where /Main is the url for the main-servlet.

    This wil work in the development-environment and in the production-environment.

    • July 7, 2009 at 10:20 pm
      Permalink

      Would be nice to see the code of what you mean, you need to escape it I think

Comments are closed.