Search code examples
pythongoogle-app-enginewebapp2

Serve static files through a custom handler or register in app.yaml?


In a project I'm developing I'm using several Python projects as dependencies. These projects each come with static files (JavaScript, images, etc.) and a set of handlers (with default URLs). To register the URLs for the handlers I add them to the routes in the WSGI application. The static files however need to be registered in the app.yaml. This is something I would like to avoid so it becomes a breeze to register both handler URLs and static files.

I thought about implementing a request handler that takes a file location and serves it with HTTP cache (like I think the default static handlers do).

I've discussed the idea with a colleague and he thought this was a bad idea. He told me that when registering the static files in the app.yaml the files are served in a more optimized way (possibly without Python).

Before I go and implement a static handler I'd like to hear what would be the pros/cons of both methods and if the static handler idea is a good idea.

In current projects we let Buildout generate the app.yaml from a template. The static files are added there. The (obvious) downside is that this process is error prone (if done automatically) or redundant (if done manually).


Solution

  • Use the static handler:

    • You don't need to startup an instance to serve your file. This generally means it'll be served quicker, and you save on CPU hours.

    • You don't have to worry edge caching.

    The cons might be that the files are static, and it might require more manual intervention with your framework.